Posts

Showing posts from January, 2023

Salesforce Fact #616 | Manual sharing removed on ownership changes

We have RowCause="Manual" when a record is manually shared with one or multiple users. When the ownership of the record changes, only shares with this condition are removed from the share object. Reference:  https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_bulk_sharing_creating_with_apex.htm?_ga=2.118149249.925916126.1675108192-1012046689.1674247969

Salesforce Fact #615 | Sharing using Sharing set

A sharing set grants site users access to any record associated with an account or contact that matches the user's account or contact. However, Record access granted to users via a sharing set isn't extended to their superiors in the role hierarchy. Reference :  https://help.salesforce.com/s/articleView?id=sf.networks_setting_light_users.htm&type=5

Salesforce Fact #614 | Remove common in flow assignment

Image
We have a 'Remove Uncommon' operator in flow assignment operation. But in case we need to figure out the uncommon ones i.e. we need to remove the common ones, we need to implement a bit of logic using loop and contains check. Attached are the screenshots.

Salesforce Fact #613 | Screen flow: Relate multiple contacts for an account

Image
Many times we need to relate an account with multiple existing contacts. We can create a screen flow with a contact lookup element to achieve this. Attached are the screenshots.

Salesforce Fact #612 | VF: access apex data in JS methods

Image
We can access data from apex controller in JS methods in vf page. Attached are the screenshots.

Salesforce Fact #611 | Set of Ids to List of Ids during deletion

Image
Suppose we are having a map of sobject records. In the key, it has a value for each entry but the value might be empty for that corresponding entry. We need to delete the sobject records in the map. In that case, we can convert the keySet() of the map to a List of Ids and perform the deletion. Attached is the screenshot.

Salesforce Fact #610 | Reason for membership in public group

Image
While adding users to public group, considering the 'Grant access using hierarchies' checkbox is selected there is an interesting thing about the reason for membership. If the user who is getting added is also placed above in the role hierarchy of one of the other members in public group, upon getting added to the public group the reason for membership for that user is shown as 'Group Member'. Now, if the user is removed from the public group, the reason for membership shows as 'Manager of Group Member' because of the access through role hierarchy. Attached are the screenshots.

Salesforce Fact #609 | Idempotent operations

Here are some of the operations in Salesforce which if done multiple times, works as if it has been done only once and also does not throw any error: 1) Record lock and unlock using apex. 2) Adding users to public group or queue from apex.

Salesforce Fact #608 | Add multiple users in public group using lookup in screen flow

Image
Many a times we need to add multiple users in public groups. We can definitely do that using the OOTB options. We can create a screen flow with multi select user lookup to achieve the same as well. Attached are the screenshots.

Salesforce Fact #607 | LWC show toast record is locked

Image
Records can be locked in Salesforce due to various reasons like Approval process or from apex code. We can create an LWC component to show a visual indicator to the user that the record is locked so that he/she gets aware before making any update in the record. Attached are the screenshots.

Salesforce Fact #606 | getters in Address class

Image
We have a couple of getter methods in Address class. So, while fetching the address field values in SOQL, it is not needed to select each address part field. We can make use of these getters to get the data. Reference:  https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_system_Address.htm#apex_system_Address_getCity Attached are the screenshots.

Salesforce Fact #605 | HasOpportunityLineItem LWC

Image
Similar to using in Flow, Validation rules, SOQLs, HasOpportunityLineItem field can be used in LWC as well to detect whether the opportunity has any line item associated. Attached is the screenshot.

Salesforce Fact #604 | OFFSET limitation

Image
We can use OFFSET clause in SOQL subquery only if the outer query has LIMIT as 1. Reference:  https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_offset.htm Attached is the screenshot.

Salesforce Fact #603 | Search undefined... in screen flow lookup

While using Lookup component in screen flow, sometimes we see that the placeholder text on that field shows Search undefined... instead of the Search <ObjectName>. The reason for this is the lookup field is not added to the page layouts of the source object which are assigned to running users. Reference:  https://help.salesforce.com/s/articleView?id=sf.flow_ref_elements_screencmp_lookup.htm&type=5

Salesforce Fact #602 | Filter on currency field for particular currencyisocode

Image
We can filter records based on a currency field for a particular value of a currency in SOQL.  For example, if we want to fetch the opportunity records whose amount is greater than the equivalent value of 500000 in EUR, we can use the below SOQL: SELECT Id, Amount, CurrencyIsoCode  FROM Opportunity  WHERE Amount > EUR500000 LIMIT 3 It takes into consideration the currency conversion rate and fetches data accordingly. Reference:  https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_querying_currency_fields.htm Attached is the screenshot.

Salesforce Fact #601 | first in apex:repeat

Image
There is an attribute named 'first' in apex:repeat which works similar to offset in SOQL. The number specified in the offset is equal to the number of rows which will be skipped. Reference:  https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_repeat.htm Attached are the screenshots.

Salesforce Fact #600 | Remove first and last occurrence of char from string

Image
There is a method named substringBeforeLast() in String class which is helpful in getting the substring before last occurrence of a particular character. Suppose, we wrapped a particular string with a particular char at the start and also at the end. Now, to get the exact string we need to remove the very first and very last occurrence of that char.  substringBeforeLast() method along with the substring() method could be handy here. Attached is the screenshot.

Salesforce Fact #599 | Deleting CaseComment records

Image
While deleting CaseComment records, recordIds won't work with Database.delete() DML statement. We need to specify as single or list of sobject records. Reference:  https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_casecomment.htm Attached is the screenshot.

Salesforce Fact #598 | ES11 Optional Chaining Operator

Image
With ES11 in JS, we now have the optional chaining operator which is similar to the safe navigation operator in apex. Reference:  https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining Attached is the screenshot.

Salesforce Fact #597 | Reusable LWC for string manipulating methods

Image
Many times we have requirement to have input text as uppercase or lowercase to be set automatically. We can create a reusable LWC component which would have all these functions and we would pass the text value as input to those functions. In this example, we have two inputs in the LWC component where the first input should be lowercase and second input should be uppercase set automatically. We have created a reusable LWC component having the two public methods and calling them from the onchange handlers. The reusable component can further be modified to have additional string functions as per the requirement. Attached are the screenshots.

Salesforce Fact #596 | SystemModStamp field is not writeable

Image
We have some setting and permission using which we can set the audit fields in the records. The audit fields include the fields: CreatedDate, LastModifiedDate, CreatedById, LastModifiedById. The SystemModStamp field however cannot be updated with this approach and this field is not writeable. Attached is the screenshot.