Lightning – Create or Place a Component Dynamically.

Your Mark.up

<div aura:id="YOUR_DIV_ID"/>

Your Controller.js

DoInit:function(component, event, helper){
                      {"recordId": t },
                      function(cmp, status, errorMessage){
                           var divComponent = component.find("YOUR_DIV_ID");
                             if (divComponent.isValid()) {
                                   var body = divComponent.get("v.body");
                                   body =[];

References :

The syntax is:

$A.createComponent(String type, Object attributes, function callback)

Type—The type of component to create; for example, “ui:button”.
attributes—A map of attributes for the component, including the local Id (aura:id).
callback(cmp, status, errorMessage)—The callback to invoke after the component is created. The callback has three parameters.
cmp—The new component created. This enables you to do something with the new component, such as add it to the body of the component that creates it. If there’s an error, cmp is null.
status—The status of the call. The possible values are SUCCESS, INCOMPLETE, or ERROR. Always check the status is SUCCESS before you try to use the component.
errorMessage—The error message if the status is ERROR.


Get URL Param Value in Lightning

First Script

getParameterByName : function (name, url) {
    if (!url) {
      url = window.location.href;
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));


// query string: ?foo=lorem&bar=&baz
var foo = getParameterByName('foo'); // "lorem"
var bar = getParameterByName('bar'); // "" (present with empty value)
var baz = getParameterByName('baz'); // "" (present with no value)
var qux = getParameterByName('qux'); // null (absent)

 Second Script :

getUrlParameter: function(sParam)
var sPageURL = decodeURIComponent(,
sURLVariables = sPageURL.split(‘&’),

for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split(‘=’);
if (sParameterName[0].toLowerCase() === sParam.toLowerCase()) {
return sParameterName[1] === undefined ? true : sParameterName[1];





Input Only Digit Script


$(document).ready(function (){
//called when key is pressed in textbox
$(“#FieldID”).keypress(function (e) {
//if the letter is not digit then display error and don’t type anything
if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
//display error message
$(“#errmsgID”).html(“Digits Only”).show().fadeOut(“slow”);
return false;



.errmsg{color: red;}

Html Code

<div class=”form-group”>
<label class=”control-label col-sm-3″ id=”routingNumberlabel”>Routing Number *</label>
<div class=”col-sm-2″>
<input class=”form-control echeckInput” type=”text” id=”FieldID” name=”x_routingNumber” size=”9″ maxlength=”9″ />
&nbsp;<span class=”errmsg” id=”errmsgID”></span>


What is Trigger?

A trigger is Apex code that executes before or after the following types of operations:

  1. insert
  2. update
  3. delete
  4. merge
  5. upsert
  6. undelete(Only After)

There are two types of triggers:

1) Before triggers are used to update or validate record values before they’re saved to the database.

2) After triggers are used to access field values that are set by the system (such as a record’s Id or LastModifiedDate field), and to effect changes in other records, such as logging into an audit table or firing asynchronous events with a queue.

The records that fire the after trigger are read-only.

Triggers can also modify other records of the same type as the records that initially fired the trigger. For example,

If a trigger fires after an update of contact A, the trigger can also modify contacts B, C, and D.Because triggers can cause other records to change, and because these changes can, in turn, fire more triggers, the Apex runtime engine considers all such operations a single unit of work and sets limits on the number of operations that can be performed to prevent infinite recursion. See Understanding Execution Governors and Limits


Why we use trigger?

Some time we need to change in parent record information or child record information or related record information. So to do this we need to write trigger.

By writing trigger

  • we can run our apex code and do what you want to do by custom code.
  • Work flow can only do more than just simple field updates, task create , outbound messaging and emails.

Workflow can’t do below task :

  • Your workflow can’t create or update a separate object!
  • You’re not allowed to reference certain fields, like Owner.Name (why Salesforce, why!)

How to create Trigger in Salesforce?

For Custom object

  1. From Setup, click Create | Objects and click the name of the object you just created.
  2. In the triggers section, click New.
  3. In the trigger editor, delete the default template code and enter this trigger definition:

Apex Code Syntax:

trigger on (before insert,before update ,before delete, after update,after insert , afterdelete,after undelete ){


For Native Object:

  1. From Setup, click Customize | Click on object and find the trigger link and then click on new button.

There are some variable by which you can get the record’s.

  1. –> Returns a list of the new versions of the sObject records.
  2. Trigger.old –> Returns a list of the old versions of the sObject records.
  3. Trigger.newMap –> A map of IDs to the new versions of the sObject records.
  4. Trigger.oldMap –> A map of IDs to the old versions of the sObject records.
  5. size –> The total number of records in a trigger invocation, both old and new.


Below is Table by which you can know which variable give you record in which event.

Variable Name Trigger.Old Trigger.newMap Trigger.oldMap
before insert Yes null null null
after insert Yes null Yes null
before update Yes Yes Yes Yes
after update Yes Yes Yes Yes
before delete null Yes null Yes
after delete null Yes null Yes
after undelete Yes null Yes null


*Be aware of the following considerations for trigger context variables:

1) and trigger.old cannot be used in Apex DML operations.

2) You can use an object to change its own field values using, but only in before triggers. In all after triggers, is not saved, so a runtime exception is thrown.

3) trigger.old is always read-only.

4) You cannot delete

For More info

Controlling Recursive Triggers | How to invoke Trigger only once


Best Practices :

  • There should only be one trigger for each object.
  • Avoid complex logic in triggers. To simplify testing and resuse, triggers should delegate to Apex classes which contain the actual execution logic. See Mike Leach’sexcellent trigger template for more info.
  • Bulkify any “helper” classes and/or methods.
  • Trigers should be “bulkified” and be able to process up to 200 records for each call.
  • Execute DML statements using collections instead of individual records per DML statement.
  • Use Collections in SOQL “WHERE” clauses to retrieve all records back in single query
  • Use a consistent naming convention including the object name (e.g., AccountTrigger)
  • Bulkify your Code
  • Avoid SOQL Queries or DML statements inside FOR Loops
  • Using Collections, Streamlining Queries, and Efficient For Loops
  • Streamlining Multiple Triggers on the Same Object
  • Querying Large Data Sets
  • Use of the Limits Apex Methods to Avoid Hitting Governor Limits
  • Use @future Appropriately
  • Writing Test Methods to Verify Large Datasets
  • Avoid Hardcoding IDs




DreamForce 14 or DM14

Hello DF’14

As we know DF’14! near to us,(Oct 13 to Oct 16 2014) All member are preparing their stuffs, And all are very excited to meet at DM14. Many of us are waiting some new awesome announcements from “Salesforce” side.

Some of us want or excited to see Great people at Dreamforce and want to hear their thoughts.

Some of us are new developers, Hope know about DF Events. If you don’t about so don’t worry. I will let you know about DF14 in my way.

Dream Force is name of Event and it is a “Cloud Computing Community Event”. Not only It is a not a small event. According to some great personality DF is a

“Dreamforce is a source of inspiration via innovation. You know you’re going to learn something new.”

“Dreamforce is a master class on how to build a modern business.”


“ events are a great way to meet and learn from other Salesforce enthusiasts. I left with tips and tricks that I can’t wait to try out”.


Dreamforce is four days of super-concentrated learning, networking, and a whole lot of fun. Even with so much going on, it’s still easy to focus on what’s relevant to me and not feel like I’ve missed anything


“DF is annual day of like school where all comes and get together wait for new announcements. It is day of Big Business at San Francisco. It is a day for Party at with great people who make world better with technology”

What happen in DF?

In DF there are many session and MVP’s give good ideas. Evangelist and Product Manager will give info about new product of Salesforce. You can find session and event in DF by open below link

For Developers:

At Dreamforce you’ll meet Salesforce developers from around the world in the Developer Zone, and pick a learning path where you can dive deep into the code topics that interest you the most. With lots of hands-on training sessions featuring coding experts, you’ll learn new skills that’ll help you transform your career

A collective spirit of innovation has always been at the core of Dreamforce. Staying true to that spirit, we’re excited to host these innovative thinkers whose ideas are truly changing the world.

Visit at

The event organised by Salesforce.

Registration here


Customize create PDF on Quote by Apex

Hi Folks,

Recently I’ve a requirement to create a quote and their quote line items when a opportunity is created with opportunity line items. Along with quote record I need to create “Quote Pdf” in apex code.  And I’ve three quote templates so template selection should be based on some criteria.

Some points to remember :

1) Quote should be enable in your org.

2) Quote template should be in your org and it should be active. You can use standard  and custom template.

3) We can’t get the id of quote template by “Apex code” (as I think) so we need to store the ids of quote template in our custom setting so we can get the id from custom setting.

4) Important: If the creation of  “Quote”,  “Quote line items” and “Quote Pdf “in a single context than you will get error. So we need to break the thread/context and than we can create “Quote Pdf” . So basically first we have to create “Quote” reocrd and then in second thread we can create “Quote Pdf”.  If you already have “Quote”  record than you can easily create “Quote Pdf”.

5) You can get the id of template by Setup–> Customize –>Quotes –> Templates –> Now you can see the templates and click on edit link before the template name and you can get the id of template from URL.(template id will start from “0EH” prefix.

6) The Pdf name will be the name of  Quote Name, we can’t provide it by code.

Now below is your code.

//Id of Quote record.
String QuoteID = '0Q0XXXXXXXXXXX';

//Id of quote Template
String templateID = '0EHXXXXXXXXX';

//This Url create the pdf for quote
String quoteUrl = '/quote/quoteTemplateDataViewer.apexp?id=';

quoteUrl +=QuoteID;

quoteUrl +='&headerHeight=190&footerHeight=188&summlid=';

quoteUrl +=templateID ;

quoteUrl +='#toolbar=1&navpanes=0&zoom=90';

//Create pdf content
PageReference pg = new PageReference(quoteUrl) ;

//Document object of quote which hold the quote pdf
QuoteDocument quotedoc = new QuoteDocument(); 

//Get the content of Pdf.
Blob b = pg.getContentAsPDF() ;

//content assign to document
quotedoc.Document = b;

//assign quote id where pdf should attach
quotedoc.QuoteId = QuoteID ;

//insert the quotdoc
 insert quotedoc; 

I hope this will help you and save your time.


Ashlekh Gera.

Certified Developer.

Page Block Section Collapse By Default

Hi All,

Hope may you are aware of page block section behavior on Visual Force Page. Page block section is always open by default on page. Some times we need to show all page block section collapse when page is loaded on screen. So Below is the code by which we can collapse all the page block section/specific page block section will be collapse on UI.

Defalut Collapse

<apex:page sidebar="false" >

 <!-- Included Js file for jquery -->
 <apex:includeScript value="{!URLFOR($Resource.NewBootstrap, '/bootstrap/js/jquery.min.js')}"/>
 When page get load then below script will run
 and collapse all the section which are under .firstSectionClass( Element Class).
 var element= $('.firstSectionClass .hideListButton');
 for(var i = 0;i<element.length;i++)

 Below script it bind with arrow icon (Icon which are being used for collapse) which are displaying on section.
 When Icon are clicked then below script will run.
 $('.firstSectionClass .showListButton').bind('click',function(event){
 var el= $('.firstSectionClass .hideListButton');
 for(var i = 0;i<el.length;i++)

 //this --> represent currently pressed section img element. You can write any script for this element fi you want to do something on section.

 <!-- The First page block section where we are showing collapsed section -->
 <apex:pageBlock title="By Default Collapsible">

    <apex:outputPanel styleClass="firstSectionClass">

       <apex:pageBlockSection collapsible="true" title="First Collapsed Section By Default">
         First Section

       <apex:pageBlockSection collapsible="true" title="Second Collapsed Section By Default">
          Second Section



 <apex:pageBlock title="Actul Section Provide by SF (Not Collapse by Default)">

   <apex:outputPanel styleClass="SecondSectionClass">

      <apex:pageBlockSection collapsible="true" title="Third UnCollapsed Section By Default">
        Third Section

      <apex:pageBlockSection collapsible="true" title="Fourth UnCollapsed Section By Default">
         Fourth Section




Hope this will help you.
Ashlekh Gera