Posts

Showing posts from April, 2018

How to display the data on clicking of a button in salesforce Lightning

Component ---------- <aura:component implements="force:appHostable"  controller="DataList">     <aura:attribute name="accdata" type="List"/>     <ui:button aura:id="button" label="show" press="{!c.doInit}"/>      <table class="slds-table slds-table--bordered slds-table--striped slds-table--cell-buffer slds-table--fixed-layout">     <thead>       <tr class="slds-text-heading--label">         <th scope="col"><div class="slds-truncate" title="ID">ID</div></th>         <th scope="col"><div class="slds-truncate" title="Name">Name</div></th>          <th scope="col"><div class="slds-truncate" title="Site">Site</div></th>           </tr>     </thead>     <tbody>       <aura

How to delete a Records with a button in Salesforce Lightning

Apex class ----------- public class updateSiteAC {     @AuraEnabled     public static list < Account > fetchAccount() {        return [SELECT Id, name,site from Account Limit 10];     }          @AuraEnabled     public static void deleteRecord(List < String > lstRecordId) {         List<account> lstAccToDelete = new List<account>();         for(account acc : [select id,Name,site from account where id IN : lstRecordId]){             if(acc.site = 'Approved'){             lstAccToDelete.add(acc);         }                 if(lstAccToDelete.size() > 0){             update lstAccToDelete;         }             } } Basic1.cmp ---------- <aura:component controller="updateSiteAC">       <aura:attribute name="ListOfAccount" type="list" />       <aura:handler name="init" value="{!this}" action="{!c.loadAccountList}"/>         <div class="slds-gr

How to update a field value with a button in Salesforce Lightning

Apex class ----------- public class updateSiteAC {     @AuraEnabled     public static list < Account > fetchAccount() {        return [SELECT Id, name,site from Account Limit 10];     }          @AuraEnabled     public static void updateRecord(List < String > lstRecordId) {         List<account> lstAccToUpdate = new List<account>();         for(account acc : [select id,Name,site from account where id IN : lstRecordId]){             acc.site = 'Approved';             lstAccToUpdate.add(acc);         }                 if(lstAccToUpdate.size() > 0){             update lstAccToUpdate;         }             } } Basic1.cmp ---------- <aura:component controller="updateSiteAC">       <aura:attribute name="ListOfAccount" type="list" />       <aura:handler name="init" value="{!this}" action="{!c.loadAccountList}"/>         <div class="slds-grid s

Showing and hiding the button on clicking of a button in Salesforce Lightning

Baisc.cmp <aura:component>     <lightning:button label="Toggle" onclick="{!c.toggle}"/>     <ui:button label="Submit" aura:id="button"/> </aura:component> controller ---------- ({     toggle : function(component, event, helper) {         var toggleText = component.find("button");         $A.util.toggleClass(toggleText, "toggle");     } }) Style ------ .THIS.toggle {     display: none; } Lightning Application ---------------------- <aura:application extends="force:slds" >     <c:Basic/> </aura:application>

Displaying the checkbox for Records in salesforce Lightning

Apex  class ---------------- public class ContactList{  @AuraEnabled  public static WrapperClass displayData(){   WrapperClass  wrap=new WrapperClass();   wrap.conList=[select Id,Name,Email,Phone from Contact];   wrap.count=wrap.conList.size();   wrap.message='Total number of Records in the Contact';   return wrap;  }  public class WrapperClass{   @AuraEnabled public List<Contact>   conList    {set;get;}   @AuraEnabled  public Integer        count      {set;get;}   @AuraEnabled  public String         message    {set;get;}  } } Component --------------- <aura:component controller="ContactList">   <aura:handler name="init" value="{!this}" action="{!c.getData}"/>        <aura:attribute name="wrapperList" type="object"/>   <div class="slds-p-around--large">           {!v.wrapperList.message} = {!v.wrapperList.count}  

Accordion in Lightning

Data.cmp ------------ <aura:Component controller="ContactList"> <aura:handler name="init" value="{!this}" action="{!c.doInit}"/> <aura:attribute name="conList" type="List"/>         <div class="slds-m-around_x-large">                 <lightning:accordion >          <aura:iteration items="{!v.conList}" var="con">                 <lightning:accordionSection name="{!con.name}" label="{!con.Name}">                     <aura:set attribute="body">                         Name{!con.Name}<br/>                         Email{!con.Email}<br/>                         FirstName{!con.FirstName}<br/> Phone{!con.Phone}                  </aura:set>                 </lightning:accordionSection>                </aura:iteration>            </lightning:accordion>        

Tab functionality in Salesforce Lightning

TabFunctionality.cmp -------------------- <aura:component >     <aura:attribute name="selTabId" type="string" default="1" />       <lightning:tabset selectedTabId="{!v.selTabId}" >         <lightning:tab label="Clients" id="1">             <b>Regeneron</b><br/>             <b>Accenture</b><br/>             <b>IBM</b>           </lightning:tab>               <lightning:tab label="Technologies" id="2">             <b>Salesforce</b><br/>             <b>Citrix</b><br/>             <b>RPA</b>         </lightning:tab>               <lightning:tab label="Locations" id="3">             <b>India</b><br/>             <b>USA</b><br/>             <b>Canada</b>         </lightning:ta

Conditional Rendering in Lightning Component

<aura:component >     <aura:attribute name="edit" type="Boolean" default="true"/>     <aura:if isTrue="{!v.edit}">         <lightning:buttonGroup>             <lightning:button label="Refresh" />         <lightning:button label="Edit"/>         <lightning:button label="Save"/>     </lightning:buttonGroup>         <aura:set attribute="else">             <ui:button label="Edit" />         </aura:set>     </aura:if> </aura:component>

Displaying the data in Salesforce Lightning

Apex class ---------- public class AccountsController {   @AuraEnabled   public static List<Account> getAccounts() {     return [SELECT Id, name, industry, Type, NumberOfEmployees, TickerSymbol, Phone     FROM Account ORDER BY createdDate ASC];   } } AccountData.cmp ---------------------- <aura:component controller="AccountsController">   <aura:attribute name="accounts" type="List" />   <aura:handler name="init" value="{!this}" action="{!c.doInit}" />    <table class="slds-table slds-table--bordered slds-table--striped slds-table--cell-buffer slds-table--fixed-layout">     <thead>       <tr class="slds-text-heading--label">         <th scope="col"><div class="slds-truncate" title="ID">ID</div></th>         <th scope="col"><div class="slds-truncate" title="Nam

RadioButton Functionality in Salesforce Lightning

RadioButtons.cmp ---------------- <aura:component >      <ui:inputRadio text="Demo1" label="Demo1"  change="{!c.onClick}"/><br/>     <ui:inputRadio  text="Demo2" label="Demo2"  change="{!c.onClick}"/><br/>     </aura:component> RadioButtonsController.js ------------------------- ({     onClick: function(component, event) {         var selected = event.getSource().get("v.text");         alert(selected);     } }) Lightning ApplicationException -------------------------------- <aura:application extends="force:slds" >     <c:RadioButtons/> </aura:application>

Javascript message in visualforce page

<apex:page standardController="Employee__c" > <apex:form > <apex:pageBlock title="Custom objectdetails"> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!Save}" onclick="return validate()"/> <apex:commandButton value="Cancel" action="{!Cancel}"/> </apex:pageBlockButtons> <apex:pageBlocksection title="Fill the data" collapsible="True" > <apex:inputField value="{!Employee__c.Name}"/> <apex:inputField value="{!Employee__c.Email__c}"/> <apex:inputField value="{!Employee__c.Phone__c}"/> <apex:inputField value="{!Employee__c.EmpId__c}"/> <script> function validate(){ window.alert('data is saved'); } </script> </apex:pageBlocksection> </apex:pageBlock> </apex:form> </apex:page>

Duplication check for Account Email

Trigger AccountTrigger on Account(before insert,before update){ set<String> setemail=new set<String>(); for(Account a:Trigger.new){ setemail.add(a.Email__c); System.debug('values in the set'+setemail); } set<String> setdata=new set<String>();     for(Account a:[select Id,Name,Email__c from Account where Email__c in:setemail]){         setdata.add(a.Email__c);             }     for(Account a:Trigger.new){         if(setdata.contains(a.Email__c)){             a.addError('Enter unique value');         }     }}

Undelete functionality in Triggers

Trigger AccountTrigger on Account(after undelete){     List<Contact> conList=new List<Contact>();     for(Account a:Trigger.new){         Contact c1=new Contact();         c1.LastName=a.Name;         c1.Email=a.Email__c;         conList.add(c1);             }    insert conList; }

Insert,update,delete operation with Trigger context variables

Trigger AccountTrigger on Account(before insert,before update,before delete){     //using trigger context variables     if(Trigger.isInsert&&Trigger.isBefore){         for(Account a:Trigger.new){             a.Email__c='mbnchowdarysfdc@gmail.com';         }             }     else if(Trigger.isUpdate&&Trigger.isBefore){         for(Account a:Trigger.new){             a.Email__c='mandalapubrahmanaidu1993@gmail.com';         }             }     else{         for(Account a:Trigger.old){             a.addError('You cannot delete a record');         }             }         }

Trigger functionality for child to parent updation

Trigger Contacttrigger on Contact(after  update){     set<String> setcon=new set<String>();     for(Contact c:Trigger.new){        setcon.add(c.Email);     } List<Account> acclist=[select Id,Name,Email__c,(select Id,Name,Email from Contacts) from Account  where Email__c in:setcon];     Map<id,Account> mapacc=new  Map<id,Account>();     for(Account acc:accList){         mapacc.put(acc.Id,acc);         System.debug(mapacc);         System.debug('Record data is'+mapacc);               if(mapacc.containsKey(acc.Id)){            acc.Email__c='default@gmail.com';                   }                           }     update accList; }                                            

before delete in salesforce

trigger AccountTrigger on Account (before delete) { for(Account a:Trigger.old) { //collection of old records[Trigger.old] a.addError('unable to delete the record'); //a [reference variable name] //addError method used to display an error message } //Displaying an error message if the user is trying to delete an account record from salesforce }

Comparing the oldvalue and new value in trigger

trigger AccountTrigger on Account (before update) { //This event will be fired when the user updates an existing record in Account for(Account a:Trigger.new) { //collection of new records(Trigger.new) if(a.Site==Trigger.oldmap.get(a.id).Site) { //a.Site will bind the new value //getting the old value(Trigger.oldmap.get(Reference variable name.Id).Field name a.addError('value should not be the same '); //addError used to display an error message } } //Error message will be displayed only if[oldvalue==newvalue] }

Validation in trigger

Handler class ------------- public class ErrorMessage { public static void throwError(List accList) { for(Account a:acclist) { //acclist is a collection of new records if(a.site==null) { //a is the reference variable name //Accessing the field name(Reference variable.Field name) a.addError('Should not be empty'); //addError method is used to display an error message } } } } Trigger code ------------ trigger AccountTrigger on Account (before insert) { ErrorMessage.throwError(Trigger.new); //This event will be fired when the user creates a record //As soon as user clicks on save then it will check for site value.If it's empty then it will throw an error message }

Before insert in Salesforce

Handler class ------------- public class BeforeInsert { public static void doOperation(List accList) { for(Account a:accList) { //accList is a collection of new records. a.Site='brahmanaidu'; //accessing the field name with reference variable name } } } Trigger ---------- Trigger AccountTrigger on Account(before insert) { BeforeInsert.doOperation(Trigger.new); //This trigger will be fired when ever the user creates an account record //By default site value is set to brahmanaidu //Salesforce will allows to enter the site value but it's not stored in the data base }