Salesforce Certified Application Architect

Friday, 6 October 2017

Loading data withou Apex/Soql in Lightening Component .







LockerService: DOM Access Containment

LockerService enhances security by isolating Lightning components in their own namespace. Due to this, a component can only traverse the DOM and access elements created by a component in the same namespace. Let’s look at a sample component that demonstrates DOM containment.

<!--c:domLocker-->
<aura:component>
    <div id="myDiv" aura:id="div1">
        <p>See how LockerService restricts DOM access</p>
    </div>
    <lightning:button name="myButton" label="Peek in DOM" aura:id="button1" onclick="{!c.peekInDom}"/>
</aura:component>
 
 
 
 
({ /* domLockerController.js */
    peekInDom : function(cmp, event, helper) {
        console.log("cmp.getElements(): ", cmp.getElements());
        // access the DOM in c:domLocker
        console.log("div1: ", cmp.find("div1").getElement());
        console.log("button1: ", cmp.find("button1"));
        console.log("button name: ", event.getSource().get("v.name"));

        // returns an error
        //console.log("button1 element: ", cmp.find("button1").getElement());
    }
}) 


You can't use cmp.find("button1").getElement() to access the DOM element created by <lightning:button>. 

LockerService doesn't allow c:domLocker to access the DOM for <lightning:button> because the button is in the lightning namespace and c:domLocker is in the c namespace.

So, use cmp.find("myInput").get("v.name") instead of cmp.find("myInput").getElement().name. The latter doesn’t work if you don’t have access to the component, such as a component in another namespace

Add a Spinner on a Visualforce Page

Add the following snippet to your visualforce page:

<apex:actionStatus id="pageStatus">
    <apex:facet name="start">
        <apex:outputPanel >
            <img src="/img/loading32.gif" width="25" height="25" />
            <apex:outputLabel value="Loading..."/>
        </apex:outputPanel>            
    </apex:facet>
</apex:actionStatus>
 
Command Button :
<apex:commandButton action="{!doSomeAction}" rerender="rerenderId" status="pageStatus" value="Do Action"/>
 
 
The final rendered spinner will look like this:
 
spinner-gif-red Loading…

How can i use lightning design system CSS(style) on my Lightning component?

Download (SLDS) platform-agnostic CSS framework.
  • Go to below link for download latest version of salesforce lightning design system framework.
  • https://www.lightningdesignsystem.com/downloads/
  • By the ltng:require tag in lightning component we can load external CSS and JavaScript libraries after we upload them as static resources.
<aura:component>
       <ltng:require styles="{!$Resource.SLDS24 + '/assets/styles/lightning-design-system-ltng.css'}"/>
<!--Button with lightning style sheet class-->
<button class="slds-button slds-button--neutral">Button Neutral</button>
</aura:component>


Note : Instead of upload  zip in static resource you can also use extends=”force:slds” in aura application.
Sample:
<aura:application extends=”force:slds” >
</aura>

Learn Salesforce Lightning (Create Records using Lightning Components) Along with Spinner Loader on button Click

Create Lightning Component :

<aura:component controller ="CreateCandidateRecordYY" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,
                            force:hasRecordId,forceCommunity:availableForAllPageTypes"
                access="global">
   <!-- <ltng:require styles="/resource/bootstrap/css/bootstrap.min.css"
                  scripts="/resource/bootstrap/js/jquery.js,/resource/bootstrap/js/bootstrap.min.js"/>-->
    <aura:handler event="aura:waiting" action="{!c.showSpinner}"/>
    <aura:handler event="aura:doneWaiting" action="{!c.hideSpinner}"/>
    <aura:attribute name="candidate" type="Candidate__c" default="{'sobjectType': 'Candidate__c','First_Name__c': '','Last_Name__c': '','Email__c': '','SSN__c': ''}"/>
    <aura:attribute name="Spinner" type="Boolean" default="false"/>
    <aura:if isTrue="{!v.Spinner}" >
        <div class="slds-spinner_container">
            <div role="status" class="slds-spinner slds-spinner--medium slds-spinner--brand">
                <span class="slds-assistive-text">Loading</span>
                <div class="slds-spinner__dot-a"></div>
                <div class="slds-spinner__dot-b"></div>
            </div>
        </div>
    </aura:if>
    <Center>
    <div class="container-fluid">
        <h3>Please Enter The Candidate Information</h3>
        <div class="form-group">
            <label>First Name</label>
            <ui:inputText class="form-control" value="{!v.candidate.First_Name__c}"/>
        </div>
        <div class="form-group">
            <label>Last Name</label>
            <ui:inputText class="form-control" value="{!v.candidate.Last_Name__c}"/>
        </div>
        <div class="form-group">
            <label>Email Address</label>
            <ui:inputText class="form-control" value="{!v.candidate.Email__c}"/>
        </div>
        <div class="form-group">
            <label>Emp Number</label>
            <ui:inputText class="form-control" value="{!v.candidate.SSN__c}"/>
        </div>
    </div>
    <div class="col-md-4 text-center">
       <ui:button class="slds-button slds-button--neutral" press="{!c.create}">Create</ui:button>
  </div>
    </Center>
</aura:component>

Create Lightning Controller:

({
    create : function(component, event, helper) {
        console.log('Create record');
       
        //getting the candidate information
        var candidate = component.get("v.candidate");
       
        //Validation
        if($A.util.isEmpty(candidate.First_Name__c) || $A.util.isUndefined(candidate.First_Name__c)){
            alert('First Name is Required');
            return;
        }           
        if($A.util.isEmpty(candidate.Last_Name__c) || $A.util.isUndefined(candidate.Last_Name__c)){
            alert('Last Name is Rqquired');
            return;
        }
        if($A.util.isEmpty(candidate.Email__c) || $A.util.isUndefined(candidate.Email__c)){
            alert('Email is Required');
            return;
        }
        if($A.util.isEmpty(candidate.SSN__c) || $A.util.isUndefined(candidate.SSN__c)){
            alert('SSN is Required');
            return;
        }
        //Calling the Apex Function
        var action = component.get("c.createRecord");
       
        //Setting the Apex Parameter
        action.setParams({
            candidate : candidate
        });
       
        //Setting the Callback
        action.setCallback(this,function(a){
            //get the response state
            var state = a.getState();
           
            //check if result is successfull
            if(state == "SUCCESS"){
                //Reset Form
                var newCandidate = {'sobjectType': 'Candidate__c',
                                    'First_Name__c': '',
                                    'Last_Name__c': '',
                                    'Email__c': '',
                                    'SSN__c': ''
                                   };
                //resetting the Values in the form
                component.set("v.candidate",newCandidate);
                alert('Record is Created Successfully');
            } else if(state == "ERROR"){
                alert('Error in calling server side action');
            }
        });
       
        //adds the server-side action to the queue       
        $A.enqueueAction(action);

    },
   
    showSpinner: function(component, event, helper) {
       // make Spinner attribute true for display loading spinner
        component.set("v.Spinner", true);
   },
   
 // this function automatic call by aura:doneWaiting event
    hideSpinner : function(component,event,helper){
     // make Spinner attribute to false for hide loading spinner   
       component.set("v.Spinner", false);
    }
})

 Create Apex Controller:

public class CreateCandidateRecordYY {
    @AuraEnabled
    public static void createRecord (Candidate__c candidate){
       
        try{
            System.debug('My Record===>'+candidate);
           
            if(candidate != null){
                insert candidate;
            }
           
        } catch (Exception ex){
           
        }
       
    }   
}
 

Create Lightning Application:

<aura:application extends="force:slds">
    <aura:dependency resource="c:LighteCreate" />
    <c:LighteCreate />
</aura:application>


Click Update Preview Button :

 

 

 

 

Monday, 18 September 2017

Duplicate Record in the list if(Trigger.isBefore){ if(Trigger.isUpdate){ for(Demand_List__c dl: Trigger.new){

trigger Updaterocord on ABC (after update,before update){

if(Trigger.isBefore){    
        if(Trigger.isUpdate){
            for(ABC  dl: Trigger.new){

if(Trigger.isAfter)
     {    
        if(Trigger.isUpdate){
            Set<String> leanAccNo = new Set<String>();
            Map<String,Decimal> loanAccNoEmicountMap = new Map<String,Decimal>();
            for( Demand_List__c dl: Trigger.new){
                if(dl.External_DL_ID__c != null && dl.External_DL_ID__c != ''){
                    loanAccNoEmicountMap.put(dl.External_DL_ID__c,dl.EMI_Count__c);
                    leanAccNo.add(dl.External_DL_ID__c);
                }
            }
           
            for(Client_Repayment_History__c obj : [select Loan_Account_No__c,Total_no_of_Meetings_conducted__c,Total_no_of_Meetings_attended__c from Client_Repayment_History__c where Loan_Account_No__c in :leanAccNo]){
                LoanAccountMap.put(obj.Loan_Account_No__c,obj.Id);
                updateRpHistObjList.add(obj);
               
            }
            for( Demand_List__c dl: Trigger.new){
                // Inital Status: Not Collected Final Status: Full Collection/ Partial Collection/Excess Collection
                if(dl.RecordTypeId == SBLoanDLRecordTypeId &&(dl.Product_Code_Formula__c ==Productcodefor814 || dl.Product_Code_Formula__c ==Productcodefor815 || dl.Product_Code_Formula__c == Productcodefor819 || dl.Product_Code_Formula__c ==Productcodefor802 || dl.Product_Code_Formula__c ==Productcodefor875 || dl.Product_Code_Formula__c ==Productcodefor876 ) && (dl.Collection_Status__c != Trigger.oldMap.get(dl.Id).Collection_Status__c && Trigger.oldMap.get(dl.Id).Collection_Status__c == notCollectedStatus  && (dl.Collection_Status__c == CollectedStatus || dl.Collection_Status__c == excessCollectedStatus   || dl.Collection_Status__c == partialCollectedStatus   )) &&  (dl.SMC_customer_attendance__c != null) ){
                 //EMI Count =1
                    if(dl.EMI_Count__c == 1){
                        //insert Client_Repayment_History__c
                        Client_Repayment_History__c rphistObj = new Client_Repayment_History__c();
                        rphistObj.Loan_Account_No__c = dl.External_DL_ID__c;  
                        rphistObj.Loans__c = dl.Loans__c;                      
                        rphistObj.Client_Name__c = dl.Clients__c;
                        rphistObj.Total_no_of_Meetings_conducted__c = 1;
                        if(LoanAccountMap.containsKey(dl.External_DL_ID__c)){
                            rphistObj.Id = LoanAccountMap.get(dl.External_DL_ID__c);
                        }
                        if( dl.SMC_customer_attendance__c == 'Yes'){
                            rphistObj.Total_no_of_Meetings_attended__c =1;
                        }else if( dl.SMC_customer_attendance__c == 'No'){
                            rphistObj.Total_no_of_Meetings_attended__c =0;                          
                            upsertRpHistObjList.add(rphistObj);
                        }
                    }
                    else{
                        loanAcctNoMap.put(dl.External_DL_ID__c,dl.SMC_customer_attendance__c);                
                    }
                }
                if(dl.RecordTypeId == SBLoanDLRecordTypeId && (dl.Collection_Status__c == CollectedStatus || dl.Collection_Status__c == CollectedStatus) && dl.PAR_Bucket__c != null && dl.Clients__c != null && dl.SMS_Partial_Collected_Flag__c == false &&dl.Clients__r.Zone__c !='Duplicate' && dl.Clients__r.Zone__c !='Invalid' && dl.OD_Amt__c != null){
                    odset.add(dl.Clients__c);
                }              
            } // End of for loop
            System.debug('loanAcctNoMap===>'+loanAcctNoMap);
     if(!loanAcctNoMap.isEmpty()){
        //updateRpHistObjList = [select Loan_Account_No__c,Total_no_of_Meetings_conducted__c,Total_no_of_Meetings_attended__c from Client_Repayment_History__c where Loan_Account_No__c in :loanAcctNoMap.keySet()];
        for(Client_Repayment_History__c rphistObj : updateRpHistObjList){
            if(!loanAccNoEmicountMap.isempty() && loanAccNoEmicountMap.containsKey(rphistObj.Loan_Account_No__c) && loanAccNoEmicountMap.get(rphistObj.Loan_Account_No__c) != 1){
                rphistObj.Total_no_of_Meetings_conducted__c += 1;
                if(loanAcctNoMap.get(rphistObj.Loan_Account_No__c) == 'Yes')
                 rphistObj.Total_no_of_Meetings_attended__c += 1;  
                 upsertRpHistObjList.add(rphistObj);
            }
        }
     }    
      if(!upsertRpHistObjList.isEmpty()){
        system.debug('@@@@ Upsert Repayment History');
        upsert upsertRpHistObjList ;
     }
        }// End of isUpdate
     } // End of isAfter
}
}
}

Refrer map loanAccNoEmicountMap in above trigger 

Wednesday, 12 April 2017

How to Use Loader in SFDC .

<style>
    /* This is for the full screen DIV */
    .popupBackground {
        /* Background color */
        background-color:black;
        opacity: 0.20;
        filter: alpha(opacity = 20);
   
        /* Dimensions */
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
        z-index: 998;
        position: absolute;
       
        /* Mouse */
        cursor:wait;
    }

    /* This is for the message DIV */
    .PopupPanel {
        /* Background color */
        border: solid 2px blue;
        background-color: white;

        /* Dimensions */
        left: 50%;
        width: 200px;
        margin-left: -100px;
        top: 50%;
        height: 50px;
        margin-top: -25px;
        z-index: 999;
        position: fixed;
       
        /* Mouse */
        cursor:pointer;
    }
</style>  

    <apex:actionStatus id="statusSaveTrip" stopText="">
    <apex:facet name="start">
        <div>
            <div class="popupBackground" />
            <div class="PopupPanel">
                <table border="0" width="100%" height="100%">
                    <tr>
                        <td align="center"><b>Please Wait</b></td>
                    </tr>
                    <tr>
                        <td align="center"><img src="{!$Resource.ImageProp}"/></td>
                    </tr>
                </table>
            </div>
        </div>
    </apex:facet>
</apex:actionStatus>

---------------------------------------------------------------------------------------------------------
<apex:commandButton id="searchBtn" value="Proceed" action="{!search}"  reRender="pMsg,enterprise1" status="statusSaveTrip"/>             

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...