Skip to main content

Posts

How to Identify whether Logged User has particular custom permission assigned ?

Earlier days we used to use Custom Permission in Visualforce page and Formula fields etc. We used to assign custom permission to a permission set. and We used to have one utility method to check whether user has permission set or not. public static  Boolean  doPermissoncheck( String  sPermissionName,  String  sUserId){      Boolean  isPermAssigned;      List < PermissionSetAssignment > lstOfAssignment      = [ SELECT   Id ,  PermissionSet . Name , AssigneeId   FROM   PermissionSetAssignment        WHERE   PermissionSet . Name  =:sPermissionName  AND   AssigneeId =:sUserId];     isPermAssigned = lstOfAssignment.isEmpty()? false : true ;      return  isPermAssigned;          } What If we want to know custom permi...

Apex programming Tricks

Convert List to Map  Lets assume we have list of accounts record and we need to create map of Id to Account record. Traditional  approach is using Iterating over list of Account records and storing in a Map. but the easiest approach is  List < Account > lstofAccount = [ Select  id,name  from   Account   limit   10 ]; system .debug( 'lstofAccount--' +lstofAccount); Map < Id , Account > map_account =  new   Map < Id , Account >(lstofAccount); system .debug( 'map_account--' +map_account); 11 : 00 : 02 : 011   USER_DEBUG  [ 4 ]| DEBUG | map_account--{ 00111000029360 TAAQ = Account :{ Id = 00111000029360 TAAQ ,  Name = Area   Agency   on   Aging   Region   9 ,  RecordTypeId = 012360000005 HcsAAE },  00111000029360 UAAQ = Account :{ Id = 00111000029360 UAAQ ,  Name = AULTMAN   HOSPITAL ,  RecordTypeId = 012360000005 HcsAAE }} Remove Dupl...

How to get record-Id in LWC screen action ?

 If you have created quick action and referred LWC component, you will get "Undefined" as Record Id in ConnectedCallback method, This is the issue I have come across.  connectedCallback() {         console.log( 'connected===============' );         console.log( this .recordId); // This will print undefined. } Solutions - 1: We can wrap LWC component with aura, and pass record Id. < aura:component   implements = "force:lightningQuickActionWithoutHeader, force:hasRecordId,force:appHostable >     < c:updateFiles   recordId="{!v.recordId}" /> </ aura:component > Solution - 2 Use RecordId in component html code. < div   style = "display:none" >      {recordId}   </ div > Component Controller import  {  LightningElement ,api,track }  from   'lwc' ; import  {  CloseActionScreenEvent...

How to display formatted value in LWC component ?

1. Hide all numbers and display only 4 digits of SSN or credit card. Declare a variable in Java Script controller that is being used in LWC component. < lightning-formatted-number   value = { ssn } ></ lightning-formatted-number >    In the java script controller  var num = '123456789234'; // you are getting SSN from apex class ssn = num.slice(-4).padStart(num.length,'*'); Console.log('ssn',ssn); 2. Append . to the end of string. var charString = 'Learning Salesforce'; charString.padEnd(30,'.'); 3. Append Currency Symbol  var testNum = 123445.34; testNum.toLocaleString('en-IN',{style:"currency",currency:'INR'}); testNum.toLocaleString('en-US', { style: 'currency',currency:'USD'}) testNum.toLocaleString('de-DE', { style: 'currency', currency: 'EUR' }) testNum.toLocaleString('en-GB', { style: 'currency', currency: 'EUR' }) 4. Display perce...

How to create Chatter Post and Notification from Flow ?

 It is very easy to create chatter post using process builder, there are many cool articles there. https://automationchampion.com/2015/10/03/getting-started-with-process-builder-part-47-mention-a-related-user-in-a-post-to-chatter-action/ This post is in regards to create notification and chatter post using flow. Use Case :We have downstream system which needs opportunity data from salesforce, we have fire and forgot integration approach to integrate both systems. Now on successful response we need to notify users that Opportunity has been pushed and one Id has been created in Downstream system. Chatter Post  1. Create Record Triggered Flow and Add your entry condition 2. Add action element 3. Select Messaging and Action as Post to Chatter 4. Create Text Template Type variable and Add your chatter message,  Even you can tag chatter post to certain users. Sometimes we can see <P><B> in the message, please remove that tag when we view message in text format in F...

How to have Chaining Promises in Lighting Component ?

We may need to call multiple apex function from aura component, each function is dependent to other function. In that case we may have call promise function inside another. Here is the sample code @AuraEnabled public   static   Opportunity  getOpportunity( String  opptyId){          return  [ select  id,name,stagename  from   Opportunity   where  id= 'opptyId' ]  } @AuraEnabled public   static   Boolean  checkFormAttached( String  opptyId){          Boolean  isNotAttached =  true ;          set < String > setOfNames =  new   set < String > { 'Admission Notification' , 'EligibilitySummary' , 'BAForm' };          List < ContentDocumentLink > contLinks = [ SELECT  id,contentd...

How to float text in lightning web component ?

 Use Case - Publish message to all users in salesforce in Home Page or any other record page.                    1. It should be easily configurable.                    2. We can stop displaying message whenever we want from a configuration. It should have Start Time and End Time. Here is my approach to achieve the same. 1. Create a custom Object Salesforce_News__c. custom fields - Start_Date__c , End_Date__c, Active__c and Message__c 2. Create record page for  Salesforce_News__c and add the page to application.  3. Create a permission set "Salesforce News configure"  which will have Create,Edit access to object Salesforce_News__c. 4. Assign permission to user who is going to configure message. 5. Create LWC component  6. Add LWC component to Home Page. Here is LWC component code. < template > < marquee >   < div   class = "slds-clearfix" ...