Posts

Showing posts from February, 2025

Salesforce Fact #917 | Screen action in action

Image
With the Spring'25 release, we now have access to Screen Actions(Beta). It takes a step ahead in the action button setup by introducing reactivity, without requiring a button click. In this example, we have created an autolaunched flow which takes the userId as input and finds out the UserTerritory2Association records for that user. We are calling the flow from the screen action which shows up the data instantly based on the user selected in lookup. No more button clicks needed! Attached are the screenshots.

Salesforce Fact #916 | Adding validation on UserTerritory2Association

Image
Suppose we would like to add validations while adding users to the territory. For example, The user should be active and the user should not be assigned to multiple territories. We can write the logic in an after insert trigger on UserTerritory2Association object. Attached are the sample code snippets.

Salesforce Fact #915 | Issue with criteria based sharing rule in before trigger

Image
Do you know criteria based sharing rules work asynchronously, hence they don't work as expected in before insert triggers. In this example, we have two object Account(Parent) and Agent(Child) and there is lookup relationship present. Now, we have created a criteria based sharing rule on account such that it is in effect when the account number is 1234. While creating an agent record we are creating an account record and setting the account owner explicitly to test out the sharing rule. We encounter an error while creating a new agent record and the account lookup is populated with some value. However, it works fine with owner based sharing rules. Reference:  https://salesforce.stackexchange.com/questions/375247/when-does-sharing-rule-execute Attached are the screenshots. Note: The trigger code and sharing rules are only for demonstration purpose.

Salesforce Fact #914 | Rerender in Aura to refresh screen flow

Suppose we have created an aura component which embeds a screen flow and it is used as the New button override for the Contact object. Now, while creating record from the Contact related list in the Account detail page we are passing the current account id by parsing the URL. Now, if we leave the screen flow midway and open another account record without refreshing the page and click on the new button on contact related list, it lands on the same page where we had left and the accountId passed is also the old one. To resolve this, we can add the below piece of code in the renderer JS: ({      // Your renderer method overrides go here rerender : function(cmp, helper){     this.superRerender();     // do custom rerendering here      $A.get('e.force:refreshView').fire(); } }) With this code added, every time the flow is invoked it gets the correct accountId and starts from first screen.

Salesforce Fact #913 | Access selected record field values in screen flow lookup w/o Get Records

Image
Suppose we are using the Lookup element in the screen flow and once a record is selected, we would like to get the value from other fields. Now, Lookup provides record Id and record Name field values by default. So in order to get the other field value we need to use a Get Records. But hold on! There is an option to get the field values without using a Get Records element. We need to define a child sobject variable and then in the advanced section, set the parent field Id with the record Id of the selected record in Lookup. In this example, we have a lookup of Account record and we are using a Contact record variable and setting the AccountId field with the selected record Id and later on accessing the field values from account. Attached are the screenshots.

Salesforce Fact #912 | Screen flow footer button visibility issue

If we are using a screen flow on any button click and for the particular app, there is utility bar present. In that case, the footer buttons get hidden in the utility bar. To resolve this, we can hide the standard footer section and use the Flow button bar component from UnOfficialSF and add extra blank sections to cover the space. Reference:  https://salesforce.stackexchange.com/questions/410593/flow-footer-being-hidden-for-utility-item-bar  

Salesforce Fact #911 | Creating Location records from apex

Have you encountered this error:  DML requires SObject or SObject list type: System.Location. While creating Location records from apex, we need to specify the type as Schema.Location, else we get the above error. Sample code: Schema.Location lc = new Schema.Location(); lc.Name = 'Test location'; insert lc; Reference:  https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007X80VFSAZ

Salesforce Fact #910 | Picklist Contains operator in flow Get Records with translation

Image
Similar to apex, we need to be careful while using Contains operator in flow along with picklist translation. In this example, we have added the french translation for the Account Industry picklist value 'Banking'. Now, while using Contains operator on the Industry picklist in Get Records element, it works fine for English language but does not work for French language. No records are fetched in the Get Records for french user. To resolve this, we need to remove the Contains check from the Get Records and check the same by adding a decision element afterwards. Attached are the screenshots.

Salesforce Fact #909 | Editable date column in lightning datatable

Image
In lightning datatable, if we have a date format editable column we can use the type as 'date' or 'date-local'. If we use 'date' the editable window shows the time part also, using 'date-local' shows only date part. Reference:  https://developer.salesforce.com/docs/component-library/bundle/lightning-datatable/documentation Attached are the screenshots.