Posts

Showing posts from January, 2025

Salesforce Fact #908 | Check if current org is sandbox in LWC

Image
How to check if the current org is sandbox in LWC? One option is to call an apex method and get the data. Another option is we can use a custom field and LWC to get the data. In this approach, we create one formula field on the User object to store the current org id and then using this one, we get the IsSandbox value using getRecord on Organization object. Attached are the screenshots.

Salesforce Fact #907 | Session based PS in Apex

Image
The object SessionPermSetActivation stores the active Session based PS assignments. We can insert data in this object from apex as well. If you encounter the error 'Field is not writeable: SessionPermSetActivation.AuthSessionId' then you need to enable the system permission: 'Manage Session Permission Set Activation' for the user. Reference:  https://salesforce.stackexchange.com/questions/310240/sessionpermsetactivation-doesnt-work-according-to-specification Attached is one sample code snippet.

Salesforce Fact #906 | Enable Lightning Login

Lightning Login is a passwordless, faster login approach we have in Salesforce. Let's see how we can enable it for the users. Go to Quick Search -> Session Settings -> Under Lightning Login, check 'Allow Lightning Login' checkbox, if we want to make the feature available based on permission set, we select the checkbox 'Allow only for users with Lightning Login User permission'. Create a PS with the 'Lightning Login User' system permission enabled ->  Assign the PS to the required users -> Login with the user and click on Enroll in Lightning Login option in User details page. And that's it! Note: Lightning login is not supported for external users. Reference:  https://help.salesforce.com/s/articleView?id=xcloud.security_ll_enable.htm&type=5

Salesforce Fact #905 | Unique Leadsource from related contacts

Image
In this blog post, I have created a screen flow to find out the unique Leadsource of related contacts for an account record. Here are the steps: 1) First we are getting the related contact records where the LeadSource is not blank for that account. Also, we are ordering the result ascending by leadsource for later processing. 2) Then we are checking if any data is found. If data is not found, showing an error screen. 3) If data is found, we are running a loop on the fetched records and checking if the previous value and current value is the same. This check is to make sure we are getting unique values and skipping the duplicate values. 4) At the end, we are showing the data in the datatable. Note: If the number of related contacts are huge, then we need to revisit this solution to avoid hitting any limits. Attached are the screenshots.

Salesforce Fact #904 | Allow user to login only using SSO

How to ensure that users can login using SSO only? First we need to enable the 'Disable login with Salesforce credentials' checkbox under Single Sign-on settings in setup -> Create a PS with the system permission 'Is Single Sign-On Enabled' checked -> Assign this PS to the intended users. Now, the users can login only using SSO, and not using username/password. Failed login attempts are shown as 'The Single Sign-On Gateway Url is invalid' in login history. Note: We should not assign this PS to admin users as they should always have option to login via username/password option to review any system issue on urgent basis. Reference:  https://help.salesforce.com/s/articleView?id=sf.sso_enforce_sso_login.htm&type=5

Salesforce Fact #903 | Check Lead coversion access in LWC

Image
How to check if the current user has access to convert lead or view and edit converted leads in LWC. User permission checks to the rescue. We can use the two user permissions: ConvertLeads and AllowViewEditConvertedLeads to check the same. Reference:  https://www.sfdcamplified.com/challenge-map-between-salesforce-permissionname-and-label/ Attached is the screenshot.

Salesforce Fact #902 | Setting record owner during lead conversion

If a Lead is owned by a Queue, then during lead conversion we need to set the ownerId to any user who will be the owner of the converted account and contact record. So while converting lead from apex code we need to set the owner id else the below error is encountered: System.DmlException: ConvertLead failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Converted objects can only be owned by users. If the lead is not owned by a user, you must specify a user for the Owner field.: [OwnerId]

Salesforce Fact #901 | Few things to consider while using Data Import Wizard

Here are two things to keep in mind while importing records with Data Import Wizard: 1) The fields available for mapping is based on the layout of the selected record type and the field level security of the user. 2) While importing records we need to select a checkbox named 'Trigger workflow rules and processes for new and updated records' in order to trigger the automations in place for that object. Reference:  https://help.salesforce.com/s/articleView?id=000387837&language=en_US&type=1