Posts

Showing posts from February, 2023

Salesforce Fact #636 | Passing filter value to Power BI field

If we are rendering some Power BI report in Salesforce record detail page and if the Power BI field name contains space then we need to tweak a bit while passing the filter value. For example, if we have a table named 'financials' and a field named 'Discount Band' in Power BI and we are filtering the data based on Name field on account, we need to use the below text formula as the filter: "financials/Discount_x0020_Band eq '"&Name&"'"

Salesforce Fact #635 | Relationship field in Create a record action

Image
When we create a new action of type 'Create a record' on the same object as the target, there is an input 'Relationship field' which is shown. This input is visible if there is any custom self lookup field created on the object. When a record is created from this action button, this field gets populated with the parent record Id automatically. In this example, we have a custom self lookup field on Contact named 'Related Contact'. This one along with the standard 'Reports To' field is visible as options. Attached is the screenshot.

Salesforce Fact #634 | Validation on opportunity deletion

Image
Suppose we need to keep a validation on Opportunity, an opportunity cannot be deleted if it has existing line items. We can make use of the HasOpportunityLineItem field in trigger. Attached is the screenshot. Note: The code snippet is only for demonstration purpose and apex best practices have not been covered.

Salesforce Fact #633 | Flow: Check of target collection is empty after filter

Image
While using collection filters in flow, if we need to check whether the target collection after the filter is empty, isNull operator does not work. Because an empty target collection after the filter has the value as []. So, we can create a dummy blank collection filter.  In this example, we have a collection filter on a list of account records. Now, in order to check the target collection is empty or not we are comparing it with a dummy blank collection filter. Attached are the screenshots.

Salesforce Fact #632 | WEEK_IN_MONTH() in SOQL

Suppose we need to find out the number of account records created grouped by the week in the month. We can use the WEEK_IN_MONTH() function in SOQL for this: SELECT WEEK_IN_MONTH(CreatedDate), Count(Id) FROM Account WHERE CreatedDate = THIS_MONTH GROUP BY WEEK_IN_MONTH(CreatedDate)    Reference:  https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_date_functions.htm

Salesforce Fact #631 | Updating object in ES7 way

Image
Now with ES7, we can use the spread operator to update object property value in JS. Attached is the screenshot.

Salesforce Fact #630 | LockType in ProcessDefinition

ProcessDefinition object stores the details of the approval processes in the org. It has a field named LockType. Each record in approval is always locked. Now based on the editability of the locked record, a locked record can only be edited by admin and by the current approvers. If the locked record can only be edited by Admin, the value of this field is 'Admin' & if the record is editable by Admin and the current approvers, the value of this field is 'WorkItem'. Reference:  https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_processdefinition.htm

Salesforce Fact #629 | Translation does not impact record type name filter in app builder

Image
If we are using record type name filter on the lightning app builder as part of conditional visibility of any component/section, it is not impacted by translation. In this example, we have put a filter on a component so that it will be visible on the record page only if the account record type name is 'Test RT1'. Now, if the translation is added for record type label in translation workbench for French language and the user language is also changed to french. The filter works perfectly in the french language context as well. However, as a best practice Record type developer name should be used  instead of record type label  to avoid any inconsistency. Attached are the screenshots.

Salesforce Fact #628 | Related account industry validation using trigger

Image
Suppose we have a scenario where we need to put a validation such that the industry of the related account should be the same on contact. If we update the related account on contact record, it needs to be of the same industry. This can be implemented using trigger logic. Attached is the screenshot. Note: The code snippet is only for demonstration purpose and coding best practices have not been covered.

Salesforce Fact #627 | Passing list of Sobject across batch apex

Image
Suppose we need to pass List<Sobject> records from one batch apex to another. We can call the 2nd batch from finish method of the 1st one and pass the list of records. In this example, we are creating 5 account records in batch1 and then passing the records to batch2 from the finish method of 1st batch. In this case, we need to use the  Iterable<SObject> type and the 1st batch needs to implement Database.Stateful interface to retain the value. Attached are the screenshots.

Salesforce Fact #626 | getUpdated and getDeleted methods

Image
There are methods in Database class which can get us the list of records of a particular SObject type which got updated/deleted within a particular interval. Database.getUpdated() and Database.getDeleted() are the two methods. Also, it does not count towards the SOQL query and rowcount limit. Reference:  https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_database.htm#apex_System_Database_getUpdated Attached is the screenshot.

Salesforce Fact #625 | Limits.getAggregateQueries()

Image
Limits.getAggregateQueries() returns the number of aggregate queries which have been process along with SOQL query statement. Basically, it considers the relationship queries on the child object. Reference:  https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_limits.htm#apex_System_Limits_getAggregateQueries Attached is the screenshot.

Salesforce Fact #624 | PS/PSG assignment removal on user license change

Image
While changing the user license, if any PS or PSG is assigned to the user that assignment gets removed. We get a popup notification as while updating the user license. Attached is the screenshot.

Salesforce Fact #623 | Manage encryption keys

'Manage Encryption Keys' system permission is the prerequisite for key management in setup. This enables the user to create tenant secrets.

Salesforce Fact #622 | Public Read/Write/Transfer

Public Read/Write/Transfer OWD setting is only available for Case and Lead objects. It allows all users to view, edit, transfer and report on all records. Reference:  https://help.salesforce.com/s/articleView?id=sf.sharing_model_fields.htm&type=5

Salesforce Fact #621 | Restrict owner update in case of manual sharing records

Image
In context of the last post, suppose we want to put a validation that if the account records have existing manual sharing records then the owner cannot be changed. We can implement the same using trigger logic. Attached is the screenshot. Note: The code snippet is only for demonstration purpose and coding best practices have not been covered.

Salesforce Fact #620 | Access share object records in trigger

Image
While changing the record owner, the sharing records with RowCause='Manual' gets deleted. If we want to access the records for some processing, we need to get them in before update context. In this example, we have an account record with two manual share records. Now, in case of before update we get correct data from the AccountShare table, in after update the records have been deleted. Attached are the screenshots. Note: The code snippet is only for demonstration purpose and coding best practices have not been covered.

Salesforce Fact #619 | DML on external objects

While performing DML on external object records we need to use either async or immediate variation functions of Database class. For example, if we try to use insert statement while inserting new records, we get the below error: System.DmlException: Argument must be of internal sObject type. use insertAsync() or insertImmediate() instead.

Salesforce Fact #618 | DoesIncludeBosses

In public group, the 'Grant Access Using Hierarchies' setting ensures the member in the higher role also get the sharing access owing to the fact of manager of group member. In the Group object, DoesIncludeBosses checkbox field represents this setting. This field is only available for public groups, not applicable to queues. The error 'IncludeBosses should only be specified for public groups: Include Bosses' is encountered while trying to set its value for queues. Reference:  https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_group.htm

Salesforce Fact #617 | Fetching field help text

While trying to fetch the field help text using SOQL on FieldDefinition object, we get the below error: No such column 'inlinehelptext' on entity 'FieldDefinition'. So, to get the help text we can use the getDescribe() call in the format: SobjectApiName.FieldApiName.getDescribe().getInlineHelpText(). For example, Account.AccountSource.getDescribe().getInlineHelpText();