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];





5 Lightning Tips for Visualforce Devs!

About an year ago, the word “Lightning” was a bit daunting, not because there were less information available to admins and developers, but as we were so used to Sales-force Classic that we were not ready to acquire this fascinating skill that time. Nowadays, things are rapidly changing and everybody is getting on to the lightning aspects. This is leading to increase in demand for LEX and Custom Component Development.

Most of the enterprises are migrating to Lightning experience from their traditional classic Salesforce application. This causes for a big ask for Salesforce developers who has hands on experience on Lightning framework.

I’ve been working on Lightning since a year and still exploring more exciting features while developing custom lightning components. So, here are some tips to help Visual-force Page Developers while working on Lighting.

1) #Lightning Component Development Tools :

Below specified tools will help you in Lightning component development.

  1. IDE – You just need to install a new version of plugin and you can directly start the component development there.
  2. Developer Console – Salesforce developer console is the most ideal one for developing the Lighting Component.
  3. Salesforce Lightning CLI – Use CLI Tool to validate your code for use within the LockerService Service Architecture.
  4. Salesforce Lightning Inspector Chrome Extension – The Salesforce Lightning Inspector is a Google Chrome DevTools extension that enables you to navigate
    the component tree, inspect component attributes, and profile component performance. The extension also helps you to understand the sequence of
    event firing and handling.
  5. Sublime Text 3 – This tool is also available for lightning development.

2) Available Documentation : It always helps us to learn a new technology or new way of development. If every thing is documented, it becomes so easy to understand and apply.
That’s why we love Salesforce Trailhead.

  • Lightning Trailheads – Apply your learning skills with the new approach provided by Salesforce. There are various trailheads added for Lightning.
  • http// – This page will show you the aura standard components along with custom developed components in your org. Just replace “yourinstance” by your own org’s instance.
  • This is a lightning component development guide.

3) Base Lightning Components : Remember, we used to refer the “Component Reference” while designing the visual-force page. Now, we have the same one for Lightning Components. But it is just that instead of Apex tags, Salesforce has added base lightning components which are useful for Lightning experience, Salesforce1 and Lightning commuties user interfaces.

For more details, refer this link – Lightning Overview


4) Error: In Development process we do mistakes and the new error log view is very useful to know where the code is breaking with new error log UI.


5)  Security Works Differently : As Visualforce developers, you have been spoiled as far as security is concerned. Visualforce apps operate out of the domain, which is not shared with Salesforce code. But, Lightning apps and components run in a special domain that is shared with Salesforce-authored Lightning code.

This means that the security for Lightning components are subject to a Content Security Policy (CSP). The rules surrounding what is and what is not allowed with these components will just tighten as time goes on. Go here to learn more about all the concerns regarding Lightning Security.

One important thing that you need to know is that any of your AuraEnabled Apex classes must do an explicit check for CRUD and FLS permissions. This was handled automatically for you in Visualforce pages, but in Lightning, unless you are using the new Lightning Data Service, you will need to do this check manually. You can do so using the isAccessible(), isCreateable(), isDeleteable(), and isUpdateable() methods. You can learn more about how this is done here.

Extras Points

6)  CSS (Cascading Style Sheets) : I really like the CSS feature of Lightning. if you are using the same class name for two different components, still you don’t have to worry about the fact that they may collapse with each other some day. (.this) allows you to separate style sheet for different components.

7) Returning Errors from an Apex Server-Side Controller :

Errors happen. Sometimes they’re expected, such as invalid input from a user, or a duplicate record in a database. When your server-side controller code experiences an error, two things can happen. You can catch it there and handle it in Apex. Otherwise, the error is passed back in the controller’s response.

When you use an AuraHandledException you have an opportunity to add some detail back into the response returned to your client-side code.

8) How to get URL Param :-



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.