Posts

Showing posts from September, 2023

Salesforce Fact #767 | INCLUDES() and PICKLISTCOUNT() combo

Image
Suppose we have a scenario where we need to check for a specific value of a multi-select picklist field in the validation rule. Now, since multi-select picklist can be checked with INCLUDES() only, it checks as per the contains logic, not for the specific value. We can make use of the PICKLISTCOUNT() function to ensure it checks only for that specific value. In this example, we have a multi-select picklist field in Account which has 3 values: A,B,C. Now, we want to create a validation rule so that when the account rating is 'Hot', the selected value should be 'A'. Attached is the screenshot.

Salesforce Fact #766 | Translation for flow custom error message

Image
With the Winter'24 release, we have the flow custom error component available for use. We can use both custom label and translation workbench to enable translation for the error message shown using this element. Attached are the screenshots.

Salesforce Fact #765 | Assigning leads to territory using data load

Image
We can now assign Leads to territories. The same can be done using data load as well. For this, we need to import records in the ObjectTerritory2Association object and specify the Lead record Id in ObjectId field. Note: If you are using DataLoader and encounter an error 'Invalid Id', please update it to the latest version. Reference:  https://forceforfun.com/2022/10/25/update-dataloader-to-take-advantage-of-assigning-leads-to-territories/ Attached are the screenshots.

Salesforce Fact #764 | Associate email to Salesforce record directly

Image
Using Email to Salesforce, we can associate the email to a record directly in Salesforce. For this, we need to specify the recordId in the subject line after the text 'ref: '. Reference:  https://help.salesforce.com/s/articleView?id=sf.email_my_email_2_sfdc_using.htm&type=5 Attached are the screenshots.

Salesforce Fact #763 | Dynamic helptext in screen flow using LWC

Image
Suppose we have a scenario in screen flow where we need to show dynamic help text for an input. Whatever value is entered in the input, the help text shows the value. We can implement this using an LWC. In this example, there is a number type input and the helptext shows the text based on the input entered. Attached are the screenshots. Note: The reactive beta feature setting needs to be enabled to pass the data from screen flow to LWC.

Salesforce Fact #762 | Navigate to next screen on checkbox select

Image
Suppose we have a scenario in screen flow where the user can navigate to the next screen only if a checkbox is checked like the terms and conditions checkbox. The next button would be disabled and once the user selects the checkbox, it will get enabled. We can implement the same using an LWC. Attached are the screenshots. Note: The reactive beta feature setting needs to be enabled to pass the data from screen flow to LWC.

Salesforce Fact #761 | Invalid email value in trigger

Image
What happens when an email field is evaluated to an incorrect value from a trigger. The below error is encountered: data changed by trigger for field <fieldName>: invalid email address: (value has been hidden) In this example, we have a dummy email field on contact which is populated with an invalid value from trigger and is eventually encountered as an error. Note: The code snippet is only for quick demonstration purpose. Attached are the screenshots.

Salesforce Fact #760 | Territory Assignment rule on account save

Image
There is a checkbox 'Evaluate this account against territory rules on save' on the Account layout to run the territory assignment rules. In order to make the checkbox visible, go to Account Page Layout -> Layout Properties -> Select show on edit page. It can also be marked as checked by default if the option 'Default' is selected. Whenever an account is assigned to a territory using the territory assignment rule, an AccountShare row is created with RowCause='Territory'. Reference:  https://help.salesforce.com/s/articleView?id=000385116&type=1 Attached are the screenshots.

Salesforce Fact #759 | AccountUserTerritory2View

There is an Sobject called AccountUserTerritory2View which tracks the users present in the assigned territories for a particular account. It basically simulates the 'Users in Assigned Territories' related list. In order to perform SOQL on this Sobject, a filter is required on the AccountId field. Reference:  https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_accountuserterritory2view.htm

Salesforce Fact #758 | Screen flow version in translation workbench

Image
If we have enabled the translation of the screen flow components using translation workbench, we need to be mindful of keeping a note of the active version. If we are deploying the new version of the flow, the translation needs to be added for the new version. Attached is one screenshot.

Salesforce Fact #757 | Default start and end time based on the input date

Image
Another example for screen flow reactivity. Suppose we have an input date field and two date/time fields in a screen flow. Now, based on the date selected the start time would be defaulted to 10 AM and end time would be defaulted to 7 PM of the same day. Attached are the screenshots.

Salesforce Fact #756 | Show approval details in VF email template

Image
Suppose we have a requirement to show the approver name, approved/rejected status and the comments in the visualforce email template which is associated to the final approval/rejection action. We can create an apex controller, VF component to implement this and refer the same in the email template. Reference:  https://gist.github.com/douglascayers/46bb1e92be9909d60fee Attached are the screenshots.

Salesforce Fact #755 | Create contacts and add to campaigns in Import Wizard

We can create contacts and add them to the campaigns at the same time using Import Wizard. For this, we need to select the checkbox, 'Assign All Contacts to Campaigns' and include the fields: Campaign Id and Member status in the csv file. Once the import is completed, a separate email is sent out with the campaign member record details. Reference:  https://help.salesforce.com/s/articleView?id=sf.campaigns_import_contacts_new.htm&type=5

Salesforce Fact #754 | Deleting share records with custom apex sharing reason

Image
While deleting share object records with apex sharing reason, if we try to delete using List<Id> it doesn't work. We can use as List<CustomShareObject> to delete the records. Attached are the screenshots.

Salesforce Fact #753 | Save one for loop using clone() method

Image
Suppose we need to find out which accounts have related contacts or no related contacts in the apex code.  Now as per the usual logic, we would fetch the data from contact object based on the AccountIds which would give us the count of accounts having related contacts. And after that, we would run another loop to iterate over the master account list and check which one does not have any related contact. Well, we can use the clone() method of Set class which would help us to save one loop. Attached is the screenshot. Note: The SOQL and list lengths are only for demonstration purpose. As per the best practice, SOQLs need to be as much as selective with proper access checks to retrieve only the intended records.

Salesforce Fact #752 | Access recordId in LWC screen action

Image
While accessing recordId in LWC screen action in other than @wire method, it shows undefined. To access the recordId value, we need to use currentPageReference. Reference:  https://salesforce.stackexchange.com/questions/344045/recordid-is-undefined-in-lwc-quick-action-component Attached is the screenshot.

Salesforce Fact #751 | Another one POC on Http Callout from screen flow

Image
We can make a GET callout from screen flow to get the calling country code for a particular country. In this example, we have a field on contact i.e Calling Country Code which is populated from the callout made from screen flow and the input is the mailing country code. The screen flow is invoked from a quick action button on the contact detail page. Attached are the screenshots.