Salesforce Certified Application Architect

Monday 13 November 2017

Component Event Vs Application Event in Lightening

Please refer below link for better understanding of events in Lightening

http://reidcarlberg.github.io/lightning-newbie/events.html

Monday 6 November 2017

When using Future calls in Apex in Salesforce

1) A future call cannot make another future call and a future call cannot be made from a batch job.
With this limitation you have to be very careful in your code that a future call is not made from within a future call. This can be very easy if the code is short or you are doing a simple web service call as described above. But if you have a complex set of triggers or workflow rules in an organization it may not be that simple.
2) Future calls cannot be guaranteed to run in a certain order.
Just because one future call was made before another future call does not mean that the first one will complete first. There are multiple queues that are running these future calls so the order cannot be guaranteed. So if you need to guarantee that actions complete in a certain order then a batch or scheduled job may be the better solution.
3) Future calls can run concurrently.

It is possible that two future methods that were executed one after the other could basically run concurrently. This means you may have to deal with record locking if these two methods could be updating the same record. This may force you to use the ‘For Update’ method on your SOQL queries, which can be difficult to troubleshoot.
4) Future calls have limits

Salesforce has limits on how many future calls can be made so they cannot be used just anywhere. There is a limit of 10 future calls per Apex invocation. There is also the limit of future calls in a 24 hour period, which is 250,000 or the number of user licenses in your organization multiplied by 200, whichever is greater. Here is a link to those limits.
Future calls have their place to solve very specific use cases. But as Salesforce developers we have to be very careful in how we use them or we will end up with code that is difficult to debug and hard to manage.

Queueable VS @future

This article is going to compare the @future and Queueable Interface.

@future Methods:
A future method runs asynchronously. And its governor limits are higher:



DescriptionSynchronous Limit Asynchronous Limit
Total number of SOQL queries 100 200
Total heap size 6MB 12MB
Maximum CPU time 10,000 milliseconds 60,000 milliseconds


When to use it:
  1. Long-running operations (callouts to external web service)
  2. Separating mixed DML operations (i.e. inserting a user with a non-role must be done in a separate thread from DML operations on other sObjects)
How to define it:

   Global class FutureClass{
         @Future(Callout=true)
             public static voidmyFutureMethod(){
                  // Perform your logic ...
             }
}

  1. future anotation
  2. Must be static and return void
  3. Specify (callout=true) to allow callouts
Limits: 

  1. Parameters passed in can be only of Primitive type
  2. Cannot chain @future method
  3. Cannot get the job ID
Queueable Interface:

This interface enables you to add jobs to the queue and monitor them which is an enhanced way of running your asynchronous Apex code compared to using future methods.
Like @future, a benefit of using the Queueable interface is that some governor limits are higher than synchronous Apex (see the table above).

When to use it comparing with @future:
  1. Chaining jobs
  2. Asynchronous monitoring (it gets job ID)
  3. Using non-primitive types


Public class AsyncExecutionExample implements Quaueable ,Database.allowcallouts{
    Public void exccute (QuaueableContext context){
      // Perform your operation here ...
    }
}

Much like what we did on using batchable interface
  1. Implement the Queueable interface
  2. Define execute() method
  3. Chain this job to next job by submitting the next job
  4. Implement the Database.AllowsCallouts interface to allow callouts
Limits:
  1. When chaining jobs, you can add only one job from an executing job with System.enqueueJob.
  2. Cannot have more than 1 job in the chain that does callouts.


 
 

Friday 27 October 2017

Salesforce Integration Interview Questions

Integration Questions & Answer:


1. what is integration ?
A. Integration is a process of connecting two applications
2. what is webservices ?
A. Webservices is a functionality or code which helps to us to do integration.
3. what is Protocal ?
A. Protocal is contains set of instructions or rules.
4. How many types of API’s avaliable in salesforce ?
A. SOAP API, REST API, Bulk API and Streaming API.
5. What is Call In and Call Out?
A. Call In is used to exposing our webservices to another users
Call Out is used to invoking or consuming our webservices to others.
6. What is WSDL ?
A. WSDL stands for Webservices Description Langugage.
It contains types, messages,port types and Binding.
7. How SOAP can be accessed ?
A. SOAP can be communicate through WSDL file, without WSDL file we can’t do integration.
Message format in SOAP is XML
8. How to do callout integration ?
A. Generate WSDL code from class
Path: setup-develop -apex class
9. Limitataions of WSDL file ?
A. File must be in .WSDL extenstion.
Multiple port types and binding will not allowed
Import and Inheritance operations are not supported.
10. What is remote site settings ?
A. Remote site settings is used to authorize the endpoint and allow us to whom integrate(end user)
11. How manys ways to XML parsing ?
A. They are two ways of XML parsing
1. XML streams
2. XML DOM
12. How to read root element in XML DOM ?
A. getroot element
13.How to read child element in XML DOM ?
A. getchild element
14.How to read all child elements in XML DOM ?
A. getchild elements
15. How to read text between tags ?
A. gettext
16. How SOAP and REST will Communicate ?
A. SOAP will communicate through WSDL file
REST will communicate through HTTP file
17. what are methods in REST
A. HTTPGET, HTTPPUT, HTTPPOST and HTTPDELETE
18. How REST can be accessed or which message format REST supports ?
A. REST supports both XML and JSON
19. What is JSON ?
JSON stands for JavaScript Object Notation. JSON is light weighted than XML

Salesforce lightning interview question and answers

Lightening Questions & Answer:

Q. What is Lightning component framework ?
A. Lightning component framework is UI framework which helps to design dynamic web apps to mobile and desktop with high responsive
Q. what is use of Lightning component framework ?
A. Lightning component framework helps to design out of box components with rich ecosystem and high performance. It is also Event-Driven architecture
Q. what are component in Salesforce Lightning ?
A. Components is a piece of code which helps to reusable to anywhere we want.
Q.Which Framework Lightning Supports ?
A. Lightning Supports component-based framework.
Q. How many types of events available ?
A. Component Event are managed by the component itself.
Application Event are handled by all components that are applying to the event. These events are essentially a traditional publish-subscribe model.
Q.What is Aura ?
A. Aura framework is builts Lightning Component framework and it helps to by apps
Q.what is SLDS stands for ?
A. Salesforce Lightning Design System
Q.What is Lightning Bundle ?
A.Lightning Bundle contains Component,Controller,Helper,style,documentation,rerender,design,SVG with it.
Q. To design Lightning components, Do we need to create a custom domain ?
A. Yes, we need to custom domain to built lightning component. By using custom domain helps use to make our organization more secure while authentication.
Q.Is it mandotary to create custom namespaces to develop lightning components ?
A. No, It’s Optional
Q. Can we access one lightning component on another lightning component in salesforce ?
A. Yes, We can able to access by using
Q. Can we access one javascript controller method on another controller method in salesforce lightning component ?
A. No, we can’t able to access
Q. Can we access one javascript helper method on another helper method in lightning Component ?
A. Yes,We can able to access
Q. Can we use external libraries in components ?
A. Yes, Lightning component supports various libraries such as Bootstrap,Gruntjs,angularJS ….
Q.By which interface helps us to show component in lightning Tabs ?
A. by adding implements=”force:appHostable”.It helps us to a component display in lightning Tabs.
Q.By which interface helps us to show component in lightning Record home page ?
A. by ading implements=”flexipage:availableForRecordHome,force:hasRecordId” and access=”global”
we can use record home page in Lightning Experience.
Q. How to make quick lightning action ?
A. with embedding script into our code implements=”force:lightningQuickAction”
Q.What are component Naming Rules in Salesforce Lightning ?
A These are Naming Rules in Salesforce Lightning
• Must begin with a letter
• Must contain only alphanumeric or underscore characters
• Must be unique in the namespace
• Can’t include whitespace
• Can’t end with an underscore
• Can’t contain two consecutive underscores
Q.How to use static resources in Lightning Application ?
A. we need show name which is stored in our static resource.
Q. What are value providers in Salesforce Lightning ?
A. Value providers helps use to access data in Lightning Application .They are two value providers as v(View) and c(controller)
v is component attribute set which helps to access component attribute values in markup
c is component controller helps us to link with event handlers and action for the component
Q. List of Global value providers ?
A. globalID
$Browser
$Label
$Locale
$Resource
Q.what is Custom Label ?
A. Custom Label helps to create multilingual applications by user language
Syntax : $A.get(“$Label.namespace.labelName”)
Q. How to add a button in Salesforce Lightning ?
A. lightning:button
Q. How to make button to work on click in Salesforce Lightning ?
A. ui:button
Q. What are list of tools are avaliable in salesforce lightning ?
A. Lightning Connect
Lightning Component Framework
Lightning Schema Builder
Lightning Process Builder
Lightning App Builder
Q.what is locker service in Salesforce Lightning ?
A. LockerService is a powerful security architecture for Lightning components. It enhances security by isolating Lightning components in their own namespace.
Q. What is @AuraEnabled ?
A. @AuraEnabled is helps to access methods in Lightning.
Q. what is Lightning Data Service in Salesforce Lightning?
A. Lightning Data Service helps to create, edit, delete and loads in component without help of apex and it shares filed level security and sharing rules to us.
Q. What is Lightning Container in Salesforce Lightning ?
A. By Lightning Container, we can access third party framework such as angularJS , reactJS. To access those developed app need to store in static resource.
Q.Which chorme extenstion helps us to debug lightning applications ?
A. Salesforce Lightning Inspector

Sunday 15 October 2017

ChildToParentUpdate Trigger in Salesforce

trigger ChildToParentUpdate on Contact (After insert,after update) {
   
    Set<Id>Setacc=new Set<Id>();
    map<id,List<Contact>>mapcc=new map<id,List<Contact>>();
    List<Account>ListAcc=new List<Account>();

    for(Contact  cc:trigger.new){
        Setacc.add(cc.accountid);
    }

    List<account>listObj=[select id,name,phone from account where id in:Setacc];
    List<Contact>ListObj1=[Select id,accountid,name,mobilephone from Contact where accountid in:Setacc];

    for(Id TempId:Setacc){
        List<Contact> TempContList = new List<Contact>();

        for(Contact cc1:ListObj1){
            if(cc1.accountid ==TempId){
                TempContList.add(cc1);
            }
        }
        mapcc.put(TempId, TempContList );

    }

    for(Account Acct : listObj) {
        List<Contact> TempContList = new List<Contact>();
        TempContList=mapcc.get(Acct.id);
            for(Contact ccs:TempContList){
                Acct.Phone= ccs.MobilePhone;
                System.debug('ListAcc1--->'+ccs.MobilePhone);
                System.debug('ListAcc2--->'+Acct.Phone);

                ListAcc.add(Acct);
            }
    }

    if(ListAcc.size()>0){
        update ListAcc;
        System.debug('ListAcc--->'+ListAcc.size());
    }

}

Trigger ParentToChildUpdate in Salesforce

trigger ParentToChildUpdate on Account (after insert,after update) {
   
    set<id>accId=new set<id>();
    List<Contact>ConList=new List<Contact>();
    Map<Id,List<Contact>>Mapcon=new Map<Id,List<Contact>>();
   
    for(Account a:trigger.new){
        accId.add(a.id);
    }
    List<Contact>ListCon=[select id,name,MobilePhone from Contact where AccountId in :accId];
    if(ListCon.size()>0){
        for(Account aa:trigger.new){
            for(Contact c:ListCon){
                if(Mapcon.get(aa.id)==null){
                    Mapcon.put(aa.id,new list<Contact>());
                }
                Mapcon.get(aa.id).add(c);
            }
        }
    }
    List<Account>ListAcc=[Select id,name,Phone from Account where Id in:accId];
    for(Account aaa:ListAcc){
        if(Mapcon.get(aaa.Id)!=null){
            List<Contact>ListCons = Mapcon.get(aaa.Id);
            if(ListCons.size()>0){
                List<Contact>ListConst = Mapcon.get(aaa.Id);
                    for(contact cc:ListConst){
                        cc.MobilePhone=aaa.Phone;
                        ConList.add(cc);
                    }
            }
        }   
    }
    If(ConList.size()>0){
        Update ConList;
    }
}

Friday 13 October 2017

How to use Lightening inspector for Lightening component debug


Custom Component to show Loading Spinner in Lightning during Server or Client side Operations

We have created a lightning component which can be used to display Loading Spinner image whenever you perform any server side (apex method call) or some complex operation on client side (component controller).


  How to use this component?


    Create a attribute in your component of boolean type to show and hide spinner.

<aura:attribute name="showSpinner" type="Boolean" default="false" />

    Add below component reference in your mark up. Here showSpinnerCmp is component name.

<c:showSpinnerCmp show="{!v.showSpinner}"/>

    In your controller just toggle the showSpinner value to true/false to display/hide spinner.

component.set("v.showSpinner",true); //to show spinner

component.set("v.showSpinner",false); //to hide spinner


You can find complete code for showSpinnerCmp component below.

You can now save this component and can used with any other component.



<aura:component >

<aura:attribute name="show" type="Boolean" default="false" />

<aura:handler name="change" value="{!v.show}" action="{!c.spinnerDisplayHandler}"/>

<div class="slds-align--absolute-center">

<lightning:spinner aura:id="spinner" variant="brand" size="large" class="slds=hide"/>

</div>

</aura:component>



--------------------------------------------------------------------------------

({

spinnerDisplayHandler : function(component, event, helper) {

console.log('show spinner value changes');

helper.showHideSpinner(component);

}

})

-----------------------------------------------------------------------------------

({

showHideSpinner : function(component) {

var showValue = component.get('v.show');

if(showValue) {

console.log('showValue'+showValue);

var spinner = component.find("spinner");

console.log('spinner'+spinner);

$A.util.removeClass(spinner, "slds-hide");

} else {

console.log('showValue'+showValue);

var spinner = component.find("spinner");

console.log('spinner'+spinner);

$A.util.addClass(spinner, "slds-hide");

}

}

})


Raising and Handling Custom Events in Salesforce Lightning

Now if we need to understand in Lightning terms, then we create different events which will be used by components to interact between them. Below are different steps for this event handling:
  • Create a Lightning event and create different attributes in it which can be used to pass information between components.
  • Component which want to fire an event needs to first register for an event by using <aura:registerEvent>. Then only it can fire an event and other component can receive it.
  • Component which wants to receive information will handle the event using <aura:handler> and type as Ligthning Event which we create.


Salesforce Certified Application Architect & Certified Data Architecture and Management Designer Exam

How to pass Salesforce Certified Data Architecture and Management Designer Exam This exam was 1st architect exam for me. Its not that muc...