Posts

Showing posts from June, 2021

Salesforce Fact #119 | Ternary limitation

Image
Suppose, we have to get the reference of an account/contact object based on a condition check. We cannot use the ternary operator for this scenario as the two return types must be compatible. So we can either cast the two object as SObjects or use the traditional if else structure to achieve the same. Attached are the screenshots.

Salesforce Fact #118 | String concatenation in formula field

Image
Here are the possible ways I have checked to concatenate text in formula fields. The result is unchanged. Attached are the screenshots.

Salesforce Fact #117 | Security Center

In order to work with security center, we need the 'Manage Security Center' system permission. Collected from: https://trailhead.salesforce.com/content/learn/modules/security-center/gather-and-review-security-data

Salesforce Fact #116 | PB and flow name conflict

Image
If there is already a process builder existing with the same name, we cannot save a flow. Even if the process is inactive, it won't allow to save. Attached are the screenshots.  

Salesforce Fact #115 | Num to text in flow

Image
Sometimes in the flow, we want the numeric values to be represented as text values for further processing. If we are getting the numeric value from a get records element, we can directly assign it to a text variable. There is no need for any additional formula and assignment to populate this. In this example, I am fetching a numeric field 'Test_Num_Field' from account and storing it directly in a text variable. Attached are the screenshots.    

Salesforce Fact #114 | Approval from flow

Image
Suppose you have a requirement to trigger an approval process from the flow and the approver should be the submitter's manager.  To implement this, we have to take one text collection variable and add the current user's manager id in it. Also we have to make sure the select approver option is set as ' Let the submitter choose the approver manually' in the approval process. Note: the hardcoded record Id is only for demonstration purpose and should be avoided as it is not a good practice. Attached are the screenshots.  

Salesforce Fact #113 | Read only flow in action

Image
Currently flow does not give any out of the box read only feature for most of the input types. However, we can make an input field read only in the screen. Suppose, we have a due date field in the screen which considers the value as 30 days past current date and this value should not be modified by the user. So, to achieve this we can add formula in the validate input section and also an error message to show to the user. Attached are the screenshots.    

Salesforce Fact #112 | Flow single record collection update

Image
For single record collection variable in flow, we can use the same one in get records and update records. No need to use another record collection variable for the update records like what we need to do for multi record collection variables. Attached are the screenshots.

Salesforce Fact #111 | Single line multi var assignment

Image
Apex also supports multi variable assignment with the same value in a single statement. I am not sure if it is a best practice, but this is super cool. :) Attached is the screenshot. For more details, please check:  https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_variables.htm

Salesforce Fact #110 | Run flows

Image
Suppose you have a flow which is launched as a quick action from the record detail page. Now you want to ensure that if the current user has the 'Run Flows' system permission then only he/she can run the flow. In that case, you can configure the same in the lightning app builder and add the condition accordingly. Attached is the screenshot. Note: In developer edition, the System admin also does not have the 'Run flows' system permission enabled.  

Salesforce Fact #109 | Power of formula

If a user cannot access a field because the FLS is disabled for his/her profile, the user can still see the data if it is used in a formula field and if he has access to the formula field. It is like the user does not see the data but still can read the data indirectly.

Salesforce Fact #108 | String concatenation in flow

Image
Suppose we need to perform string concatenation in flow for one of the object text fields and the text is added to the current field value .  We can do it using two ways. In this example, the account description is concatenated with the word 'test'. Attached are the screenshots.

Salesforce Behaviour | Sobject set ordering

Image
In case of set of sobjects, even if you add the records of different sobject in random way, the records of same sobject type are kept together. Attached are the screenshots.

Salesforce Fact #107 | Apex sharing update

Image
As part of a recent Spring'21 update, an @AuraEnabled apex controller will default to with sharing if no sharing is specified in the class declaration. In this example, there is a lightning component which shows the count of account records the logged in user has access to. For this, an AuraEnabled method is written which returns the list of accounts. Since, no apex sharing is mentioned, it defaults to with sharing. For more details, check:  https://help.salesforce.com/articleView?id=release-notes.rn_lc_apex_with_sharing_cruc.htm&type=5&release=230 Attached are the screenshots.

Salesforce Fact #106 | SobjectList consideration

Image
When using SObjectList we should instantiate the list using the new keyword so that it can contain all the object types. If we assign some sobject list directly to the variable, we won't be able to add other sobject records, even after using clear() function. Attached are the screenshots.

Salesforce Fact #105 | Single quote NULL check

Image
We can use the single quote along with comparison operator while checking for null values for text fields in SOQL. But '' and ' ' are not the same. Note: The count here is based on the records present in my org. Attached is the screenshot.  

Salesforce Fact #104 | LastName not provided

Image
When Leads are imported from Import Wizard, if the LastName is not provided, it does not show any error and the value is set as 'not provided'. Not sure how it came up in Korean in my case. :( Attached are the screenshots.

Salesforce Fact #103 | Set audit fields during import

Image
Audit fields can be set during import. For this, we need to follow the below steps: 1. We need to enable the setting ' Enable "Set Audit Fields upon Record Creation" and "Update Records with Inactive Owners" User Permissions  ' in User Interface. 2. We need to create a permission set and enable either of the system permissions:  Set Audit Fields upon Record Creation,  Update Records with Inactive Owners and assign to respective users. 3. Import the records with audit fields values set from the import file. For details, check out:  https://help.salesforce.com/articleView?id=000328426&type=1&mode=1 Attached are the screenshots.

Salesforce Fact #102 | Boolean is NULL

Image
Boolean variable doesn't default to false in apex like other programming languages. So, we need to be careful. For further details, check out:  https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_boolean.htm Attached is the screenshot.

Salesforce Fact #101 | Proceed if no error

Image
In testmethod, whenever an error happens the next lines are not executed within the testmethod. However, the next testmethod is executed as usual. But the test fails showing failed status for the method in which the error was encountered. Attached are the screenshots.

Salesforce Fact #100 | Sharing variable in test class

Image
Suppose, we want to use a variable in all the test methods of a test class. So, we can define a static variable and use that in the test methods. But the point is, every testMethod begins with a new scope i.e. whatever changes made to the variable in the previous test method is not stored. Attached is the screenshot.

Salesforce Fact #99 | Constructor code coverage

Image
While writing test classes, if we need to get the coverage for the constructor of the apex class, we need to instantiate the class using new keyword in the test class, otherwise it won't cover the constructor. Attached are the screenshots.