Posts

WAT if the owner of an account is changed then the owner of the related contacts should also be updated.

 Account Trigger ============================================ trigger AccountTrigger on Account (after update) {   Set<ID> accountId = new Set<ID>();   if(Trigger.IsAfter && Trigger.IsUpdate){     for(Account objAcc : trigger.new){       if(trigger.oldMap.containsKey(objAcc.id)){         if(trigger.oldMap.get(objAcc.id).OwnerId != objAcc.OwnerId){           accountId.add(objAcc.Id);         }       }     }     if(accountId != null && accountId.size() > 0 ){       AccountTriggerHandler.UpdateOwnerofContact(Trigger.newMap, accountId);     }   } } ============================================ AccountTriggerHandler Class public with sharing class AccountTriggerHandler {   public static void UpdateOwnerofContact(Map<Id,Account>accountMap,Set<id>accountId){     List<...

Get Interface Class List from SOQL

ApexTypeImplementor Object: Get the list of all classes which implement a particular interface with the help of ApexTypeImplementor object. List<ApexTypeImplementor> lstofbatchclass =[SELECT Id,ClassName FROM ApexTypeImplementor WHERE InterfaceName = 'Batchable']; https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_apextypeimplementor.htm

Open the Model Popup in LWC

Image
 Create the LWC //HTML FILE CODE <template>     <!-- lightning button for open modal window -->     <lightning-button variant="brand"        label="Open the Model/Popup?"        title="Open the Model/Popup?"        onclick={openModal}        class="slds-m-left_x-small">     </lightning-button>     <!--Use template if:true to display/hide popup based on isModalOpen value-->      <template if:true={isModalOpen}>         <!-- Modal/Popup Box LWC starts here -->         <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" aria-describedby="modal-content-id-1" class="slds-modal slds-fade-in-open">             <div class="slds-modal__container">               ...

Fetch Picklist value in LWC using Schema class

Image
 Create the Apex Class: public with sharing class lwcPicklistController {          //fetch picklist values from  SOBJECT     @AuraEnabled(cacheable=true)     public static List < customValueWrapper > pickListValueDynamically(sObject customObjInfo, string selectPicklistApi) {        Schema.DescribeSObjectResult objDescribe = customObjInfo.getSObjectType().getDescribe();             map < String, Schema.SObjectField > customFieldMap = objDescribe.fields.getMap();              list < Schema.PicklistEntry > custPickValues = customFieldMap.get(selectPicklistApi).getDescribe().getPickListValues();        list < customValueWrapper > customObjWrapper = new list < customValueWrapper > ();        for (Schema.PicklistEntry myCustPick: custPickValues) {         ...

Salesforce Spring 21 Release Notes points related to Salesforce Admin

Lightning Flow Is Now Salesforce Flow The Lightning Flow suite of features is now called Salesforce Flow, and it still includes all your processes and flows. Lightning Flow Builder and Lightning Process Builder are now called Flow Builder and Process Builder.

Rollup value from Child object To Parent Object Using Aggregate Result Query

Requirement: Update Total Age on Account from contact. Write a trigger on Contact, When Contact record will insert with age value update the total age on Account of child contacts, Create Age number field on Contact object Create Total Age number field on Account Object trigger updateTotalAgeonAccount on Contact (after insert,after delete ,after update) { set<Id> accountIds = new set<Id>(); list<account> updateAccounts = new list<account>(); if(Trigger.isUpdate ||Trigger.isInsert) { for(contact c : trigger.new) { accountIds.add(c.accountid); } } if(Trigger.isDelete) { for(contact c : trigger.old) { accountIds.add(c.accountid); } } //run the query to sum the data AggregateResult[] totalAges= [select  SUM(age__c)totalAge,accountId  From Contact where accountId IN:accountIds group by accountId]; System.debug('totalAges@@@'+totalAges); for(AggregateResult ar: totalAges) { Id thisAccountId...

Show the Success Message before Redirecting the Detail page on Visualforce Page

Requirement: To show the Success message before Redirecting the Detail page. On Click on Save button show the successful message after that redirect to detail page.  Solution: Create the Controller Class public class ClassName { // Create a boolean property     public boolean isChanged{get;set;}             public void SaveData(){         //Write Save/update Logic //insert/update list or object /set the boolean value as a true after list update/insert isChanged=true;         ClassName              } // This method will call after saving the record. and redirect to specify id     public pagereference redirectToRequiredPage(){         PageReference pageRef=new PageReference('/' +Recordid);         return pageRef;     } } Create the visualforce page <apex:page Contr...

How To Find Button Click Using Lightning Component

Image
Requirement: On LC there are two buttons. Both buttons have same function how to get which button have clicked. Solution Create a component ButtonClick.cmp <!--c: ButtonClicked -> <aura:component >     <aura:attribute name="whichButton" type="String" />          <p>You clicked: {!v.whichButton}</p>     <ui:button aura:id="button1" label="Click me" press="{!c.pressMe}"/>     <ui:button aura:id="button2" label="Click me too" press="{!c. pressMe }"/> </aura:component> /*  ButtonClicked Controller.js */ ({      pressMe : function(cmp, event, helper) {         var whichOne = event.getSource().getLocalId();         console.log(whichOne);         cmp.set("v.whichButton", whichOne);     } }) Create a app Test.app for Testing <aura:application extends="force:slds"> ...

Open Model Pop Up Using Lightning Component

Image
Create the Component. Component Name: ModelPop.cmp <aura:component>          <aura:attribute name="isOpen" type="boolean" default="false"/>          <div class="slds-m-around_xx-large">         <lightning:button variant="brand"                           label="OpenPopUp"                           title=""                           onclick="{! c.openModel }" />                 <aura:if isTrue="{!v.isOpen}">             <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" aria-describedby="modal-content-id-1" class="slds-modal slds-fade-in-open">       ...

Set Default Lightning Experience for users

Image
Requirement: Set Default Lighting Experience for the User based on Profile Solution: Using  Visual flow and Login flow you can achieve the solution 1) Visual Flows 2) Login Flows Step 1 : Set Up>> Flow>> New Flows Create the Variables 1) User Id 2) User Name Click on " Resources Tab " and then Double Click on Variable and fill detail as mention in snapshot Step 2 : Click on " Palette Tab " and then select the record Lookup and fill mention detail as mention below Step 3 :  This is the main step, On User object there is a standrad field UserPreferencesLightningExperiencePreferred  which one track the user is in Lightning or Classic.Setting this field to true will force the Lightning UI. And setting its value to false will force the Classic mode. Click on " Palette Tab " and then select the record Update and mention detail as mention below Step 4: Select the Screen and display the Message, T...