Posts

Showing posts from August, 2021

Salesforce Fact #171 | Pass value from LWC to VF

Image
One of the ways to pass data from LWC to VF page is through the URL. Attached are the screenshots.

Salesforce Fact #170 | More info about Testsetup()

Image
SOQL statements in Testsetup() method and not in the scope of Test.startTest() & Test.stopTest() are counted towards the total count of SOQL statements in the test class. And another point to note, every test method gets its own set of governor limit. Attached is the screenshot.  

Salesforce Fact #169 | startTest() & stopTest() in setup method

Image
Testsetup() methods can contain Test.startTest() and Test.stopTest() methods just like other test methods. Attached is the screenshot.

Salesforce Fact #168 | Picklist record field in screen flow

Image
Record fields in screen flow are in Beta and do not support all field types yet. So, suppose we have to show picklist field value from the record in the screen. In that case, we can use a picklist type field and use picklist choice set for all the options and for the default value, we can use the value from the record. In this example, we are getting the data from account and we have created a picklist field to display the account type. Attached are the screenshots.

Salesforce Fact #167 | LWC to VF navigation

Image
Navigating to a VF Page from LWC can be done using NavigationMixin.  Collected from:  https://salesforce.stackexchange.com/questions/268907/is-it-possible-to-navigate-to-a-visualforce-page-from-an-lwc-with-parameters-and In this example, calledFromLWC is the VF Page name. Attached is the screenshot.

Salesforce Fact #166 | Duplicate removal in flow without sort

Image
Suppose we have a use case where we have to fetch some account records and find out the count of unique account names inside flow. We can get the count without using any collection sort element. We can simply get this by doing exists check using the loop, decision & assignment elements. We can also develop this as a subflow to make it reusable. Attached are the screenshots.

Salesforce Fact #165 | Get Records for specific date in lightning flow

Image
Working with dates in lightning flow is always troublesome. If we use the DATETIMEVALUE() function it considers the GMT time, not the logged in user's local time. But we can get records for a particular date with some tweaks of formula fields. Suppose, we are interested to find out how many Account, Contact & Lead records were created on a particular day based. So, in this case we have to check against the createddate of the records. So, we can create two datetime formula variables to store start datetime and end datetime accordingly and use the same in the Get Records. Note: Here I have considered the time 5.5 hours less to match with the GMT time since I am in IST time. It can also be made configurable. Attached are the screenshots.

Salesforce Fact #164 | LWC: Add attribute to records of apex response collection

Image
When we are fetching the data from apex in LWC, if we need to add a new attribute to each of the record of the response collection we cannot simply add it to the original collection. We can make use of the array.map() method as it returns a new collection and we can use the spread operator to add the attribute. Attached is the screenshot.  

Salesforce Fact #163 | Multiple Sobject records deletion from flow

Image
Suppose we have a use case where we need to delete records from multiple objects in lightning flow. So we need to use multiple delete records element to do this. Instead, we can create a reusable invocable apex method which can take the recordIds which are to be deleted as input from the flow and delete all the SObject records in a single DML operation. Attached are the screenshots.  

Salesforce Fact #162 | Enable Add to Campaign for accounts

Image
In order to add accounts to campaign, we need to enable the Accounts As Campaign Members setting. Once enabled, we need to add the Campaign History related list to the account layout. Now we can add accounts to a campaign. Collected from: https://help.salesforce.com/s/articleView?id=sf.campaigns_account_campaign_member_enable.htm&type=5   Attached are the screenshots.  

Salesforce Fact #161 | Check if marketing user

We can use the UserPermissionsMarketingUser field of User object to know if Marketing User checkbox is enabled or not in the User record. This field is not visible in the object manager. But can be queried. Example: SELECT Name, UserPermissionsMarketingUser FROM User WHERE IsActive = TRUE Collected from: https://developer.salesforce.com/docs/atlas.en-us.sfFieldRef.meta/sfFieldRef/salesforce_field_reference_User.htm

Salesforce Fact #160 | Standard section removal from page layout

Image
Suppose we have a requirement to change the label of the standard information section in page layout of standard object. Now since the label is not editable for the standard information section, we need to create a new section and label it as per the need and add the fields as per our requirement. But the interesting thing is that the standard section cannot be removed until we are moving some of the important standard fields. In this example, we want to change the label of the Account Information section. But this section cannot be removed until the Account Name & Parent account fields are moved to another section. Attached are the screenshots.

Salesforce Fact #159 | Flow collection index consideration

Image
In Lightning flow, the index of collection elements start with 1. In this example, we got the errors when we are trying to access the record at 0th index and also when we are trying to access an index which is greater than the length of the collection. Attached are the screenshots.

Salesforce Fact #158 | Future methods: governor limits

Image
Future method scope gives us a new set of governor limits, just like startTest() and stopTest(). Also the SOQL statement limit is increased to 200. Attached are the screenshots.

Salesforce Fact #157 | Id accepts NULL, not blank

Image
Id type in Salesforce does not consider any blank value, it accepts only NULL. If we have a function which accepts Id type parameter, then if due to some incorrect code logic, the blank value is passed it will throw error. Similar thing goes for a function which returns an Id, if we cannot return a valid Id, we need to make sure we are returning NULL, and not blank by mistake.  Attached are the screenshots.  

Salesforce Fact #156 | Related contact count in flow

Image
We can count the number of related contacts for each account in flow and display them in the screen. We can make use of the Get Records, assignment, decision and screen elements for this. The idea is, we would fetch the records order by accountId so that we can get the same accountId records together which will help us to increment the counter. Attached are the screenshots.