Skip to main content

Posts

Showing posts from 2020

Sharing access to profile or permission set via API in Salesforce

 There are certain scenarios where we cannot or may be difficult to open up access (of object, Field, Pages or Classes) in profile or permission set directly via UI. In this article, we will see two such scenarios and check the alternate approach. Use Case : Sharing Class or Page access to profile or Permission Set via UI is not possible when your organization have a lot of classes already. The UI will throw an internal error because of heap size limit exception hit while loading all the classes from the organization. Hence We need an alternate way to share the class with profile Sometimes you receive a request to move object permissions or Field level permissions of an object during a deployment window. You are in need of faster approach to move the permissions instead of manually copying the permissions. To start with, Let’s first understand the profile data model. Each profile is linked to an underlying permission set which is the parent of the objects Setu...

Restricting Salesforce username and password login for non administrators

 In this post, We are going to see on how to restrict username/password login using Delegated authentication. Use Case: When the SSO is implemented in the organisation, Admin may want to restrict the users using a Salesforce username and password for login, so that the user always use SSO to login. To achieve this requirement in Salesforce, We are going to use Delegated authentication. Step 1: Enabling Delegated Authentication In Lightning, Go to Gear Icon > Setup > Look for Single Sign-On Settings in Quick Find > Under Delegated Authentication, select Disable login with Salesforce credentials . Once you select this option, The UI will be shown like this We don’t need to configure ‘ Delegated Authentication URL ’ and ‘Force Delegated Authentication Callout ’ for this implementation. Step 2: Enabling Delegated SSO at related Profile or Permission Set Enabling the Delegated SSO will add " Is Single Sign-On Enabled " permission at ...

When to use UserRecordAccess and ObjectShare object Salesforce

 Let us quickly see the differences between these objects, use cases, restrictions and finally why objectshare should not be used to get the access level of user in record. UserRecordAccess What is it : This object can be used to find out the user's access to a set of records. The important fields in this object are RecordId, MaxAccessLevel, HasReadAccess, HasEditAccess, HasDeleteAccess, HasDeleteAccess, HasTransferAccess and HasAllAccess. Use Case : As an admin, When you want to find out if the record can be accessed by the user or not, Or what level of access the user has on the record, This is object that will give the answer. Availability : API version 24.0 or higher. You can only query records of objects listed on the Sharing Settings Setup page. DML Restrictions: The object is Read only. We can’t create, delete, or update any records using this object. We can query maximum of 200 records at a time. When querying, Some special restrictions are a...

Logic to convert 15-character id to 18-character id Salesforce

 As we all know, Salesforce supports both 15-character id and 18-character id. Before API version 2.0, Salesforce supported only Case sensitive id. From API version 2.0 and higher, Salesforce is supporting both 15-character Case sensitive id and 18-character case insensitive id. Currently Salesforce provides some built-in options to convert the 15-character id and 18-character id. UI Creating a formula field on the object with function CASESAFEID(Id) to get the 18-char id at the record level. Apex / API When inserting or updating the records, Both 15 character id and 18 character id are accepted. Salesforce internally converts 15 character id to 18 character id to perform the operation. When querying the records, System always export the records in 18 character id. So Apex script using System.debug() or Simple API query using Developer Console or Workbench can show you 18-character id. Now coming back to actual question how to convert the 15-character id to 18 chara...

Governor Limit exception due to Rollup Summary Field Change

 Rollup Summary Field(RSF) gives an easy way to get values from related records when the two objects are related via Master -detail relationship. We can perform different types of calculations with a roll-up summary field such as count, sum, minimum value, or maximum value of a field in the detail records. I am sharing one of the platform behaviour noticed with Rollup Summary field calculation. When RSF definition is changed with an aggregated Field, Filter and Type , It will trigger Field Recalculation. When the currency conversion rates are changed, The currency fields are recalculated. As an admin, you have two options on field calculations. "Automatic calculation" option is to let salesforce decide the best time to run field Calculation. "Force a mass recalculation" option is to initiate the field calculation immediately. Whenever the field definition is changed, Depends on the calculation option selected, A background job with Type 'S...

Lightning Flow redirection to any URL with Local Action

One of the common requirements in lightning flow is to redirect to a record or to any random url after the flow is completed. In Lightning experience, This redirection can be achieved with a Local Action. We can redirect the user to any record or any URL such as tab, Related List and external URL etc. The implementation is a two step process. Create or Install the local Action to do the redirection. Add the local action to your flow with Core Action Element and pass the input to the local action. In the following example, We are creating a simple lightning flow which takes the URL as the input and redirect the user to the URL Step 1: Creating Local Action Flow Local Action calls a lightning component to achieve this redirection. Let us quickly see how this lightning component looks like navigateToUrl.cmp <aura:component implements="force:lightningQuickAction, lightning:availableForFlowActions"> <aura:attribute name="redirectURL" type="String" ...

Inserting Line breaks in Apex email message Salesforce

 To insert line breaks with setPlainTextBody method from SingleEmailMessage, Use '\n' character. Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setPlainTextBody('Hi \n \n' + 'Welcome to Gavan'); Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); To insert line breaks with setHtmlBody method from SingleEmailMessage, use <br> tag Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setHtmlBody('<html><body>Hi <br/><br/>'+'Welcome to Gavan </body></html>'); Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });