Skip to main content

Posts

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

How to get parent record Id from URL and pass to LWC component ?

Use Case - Lets assume we have custom child object named "TRW__c" to parent Lead. you need to override New button of  TRW object. Unfortunately we cant override New button with LWC, then aura is suggested approach.  Some other approach is use intermediate Visualfoce page then use lighting-out features. I'm going to explain how to use LWC component wrapped inside aura. Challenge - We will not get Lead record Id easily unlike we get if component is being used as global action. {!v.recordId} Here is the workaround to get parent record id and pass to your LWC. This will be useful when your standard button/action is overridden. LWC component name - createBAFormLWC < template >       < template   if : true = { loading } >          < lightning-spinner ></ lightning-spinner >      </ template >      < div >  BA form Id...

How to format number in Visualforce and in LWC ?

 Use Case - We want to show a number in percentage format, say if field value contains 15 then we need to show in UI as like 15%. Here is the sample code for it. <apex:outputLabel value="In-Network Copay Amount:" for="incper" style="color:#3E3E3C" >         <apex:outputText value="{0, number, ###,##0}" id="myNumberDisplay" > <apex:param value="{!Eligibility_Summary__c.In_Network_Copay_Percentage__c}"/> </apex:outputText>%  </apex:outputLabel>   LWC < div   class = "slds-col slds-size_1-of-2" >     < label > In-Network Copay Amount </ label >     < div   class = "slds-col slds-size_1-of-1" > < lightning-formatted-number   value = { summary . In_Network_Copay_Percentage__c } > </ lightning-formatted-number >      %     </ div > </ div >

How to formart Date in Visualforce page ?

 We can format date as per our need, Lets assume we want show date as Aug 8, 2021.  <apex:outputLabel value="Resident DOB:" for="doiv" style="color:#3E3E3C">           <apex:outputText value="{0,date,MMM dd,yyyy}"  id="inamsd" style="color:#080707">                <apex:param value="{!Eligibility_Summary__c.Resident_DOB__c}" />            </apex:outputText>   </apex:outputLabel>

How to show success message and error message in LWC?

1. First import  ShowToastEvent   import  {  ShowToastEvent  }  from   'lightning/platformShowToastEvent' ; 2. Add below method. showSuccess(){         this.dispatchEvent(new ShowToastEvent({           title: 'Success',           message: 'Lead has been Cloned',           variant: 'success',         }));     } 3. Call this.showSuccess(); where we want to show success message. 4. Error message showError(msg){         const evt = new ShowToastEvent({             title: 'Eligibility Error',          ...

How to get record Id from URL to pass to another LWC component ?

 Use Case : On click of button on Lead record detail, you want to open popup and do some processing on that lead record. 1. Create Aura Component to wrap LWC component. 2. LWC component has all logic. 3. Create quick action button invoke Aura component. Now how to pass record Id from URL to LWC component. <aura:component implements="force:lightningQuickActionWithoutHeader, force:hasRecordId" > <c:cloneLead recordId="{!v.recordId}" /> </aura:component> Note - After Winter 21 onwards, we don't have to warp lighting aura component for LWC. Because LWC started supporting quick actions such headless action and flow action.