Skip to main content

Posts

How to clone Lead record in apex ?

 We have standard clone button where we can clone only lead record, what if we need to clone all the child records and attachments along with Lead then apex is only options. 1. Define Quick Action "Clone", call lightning component. 2. Change layout add custom clone button in the place of Standard clone button. We have to make sure, if any custom fields added in Lead in future then cloned should have that new field populated  and should be able to be converted.  That being said we cant hardcode field name. We have to make it dynamic. Here is code block to get all fields dynamically in SOQL. // This is the set where all fields name will be stored Set < String >  fieldNames = new Set < String > (); Map < String ,  Schema.SObjectField >  fieldMap = Lead.sObjectType.getDescribe().fields.getMap(); // Get all of the fields on the...

How to close modal dialog in Lighting component ?

  Lightning Web Components Lightning Web Components are supported in Quick Action after 21, Here is the code to close popup. First Import library  import  {  CloseActionScreenEvent  }  from   'lightning/actions' ; Dispatch event when we want to close popup this .dispatchEvent( new   CloseActionScreenEvent ()); XML code < targets >    < target > lightning__RecordAction </ target > </ targets > < targetConfigs >    < targetConfig   targets = "lightning__RecordAction">      < actionType > ScreenAction </ actionType >    </ targetConfig > </ targetConfigs > Lightning Aura Components It is very easy to close aura modal, we need $A.get("e.force:closeQuickAction").fire(); Here is controller code  ({ closeMethodInAuraController : function(component, event, helper) { $A.get("e.force:closeQuickAction").fire(); } }) Lightning Aura Co...

How to load image in LWC component ?

 1. First Load your image in Static Resource. Say name -  Financial_ComingSoon    2. Import @salesforce/resourceUrl here is the syntax  import   Financial_ComingSoon   from   '@salesforce/resourceUrl/Financial_ComingSoon' ; 3. Declare a variable in export function financeLogoUrl =  Financial_ComingSoon ; 4. Refer financeLogoUrl in component. StaticResourceImageLWCExample < template >      < lightning-card   title = "My Banking and Financial " >          < div   class = "slds-m-around_medium" >              < img   src = { financeLogoUrl } >                      </ div > </ template > Here is controller code import { LightningElement } from 'lwc' ...

How to reload record page automatically from LWC component ?

 Use case - Sometime we may need to update record or create child record from a quick action. To see new value we have to refresh page automatically to avoid manual refresh by user. Assume I have quick action on Lead, which create record in Child Object also create content documents.  My quick action invoke lighting component to perform these action, now I have to refresh Lead page on successful completion. Here is code that will achieve. 1. We need to import library in JS file  import  {  updateRecord  }  from   'lightning/uiRecordApi' ; 2. @ api recordId; this will capture lead record Id 3. Add a function in JS file updateRecordView(recordId) {        console.log( 'updateRecordView called ' , this .recordId)         updateRecord({fields: { Id: this.recordId }}); } 4. Finally call updateRecordView where you are generating sucess event...

How to open a record page from finish of flow also close the flow screen ?

 Use case - Navigate to custom object record automatically from screen flow and auto close the flow screen.  Now a days flow are so advanced we need to leverage flow as much as possible to avoid apex programming.  Requirement - Create customobject__c record from Lead coping all the values from anotherCustom__c.Both objects are child to Leads.  There are many ways to achieve to do so. Below is approach I followed to achieve it. 1. Created Before trigger flow to map all the fields  of customobject__c from anotherCustom__c object. 2. Created action in Lead. That action can call lighting component, Visualforce page, and screen flow.Since I'm determined to go via less code, so I leveraged screen flow option. Screen flow contains 2 elements. A. Create Record and B. screen where one aura component loaded. 3. Create Record - This will insert customobject__c record, just mapped only one field Lead Id. Because based on Lead Id, the other flow will make query to pull ...