Posts

Showing posts from April, 2023

Salesforce Fact #667 | Get current session Id

If we use System.debug() to get the current session Id, it shows SESSION_ID_REMOVED.  So, in order to get the SessionId we can use a bit of apex logic as below: System.debug(UserInfo.getOrganizationId()+''+UserInfo.getSessionId().substring(15)); Note: The first 15 char of session Id is the Organization Id. Reference:  https://developer.salesforce.com/forums/?id=9062I000000g6v7QAA

Salesforce Fact #666 | Picklist api value with single quote

Image
Suppose we have a picklist field value whose api name contains single quote like the value: Partner's Account. In order to import the data correctly in this field, we need to wrap the value inside double quotes like "Partner's Account". Attached are the screenshots.

Salesforce Fact #665 | Dynamic maxrow selection in screen flow datatable

Image
We have a Data Table component type in screen flow. While configuring the row selection for a Data Table, if the Row selection mode is 'Multiple' we can set the min and max row selection values. Suppose, we want to keep the max row selection value dynamic i.e. it will be based on the length of the source collection and we want to allow the user to select the max number of rows which is equal to length of collection - 1. For this, we can take a number type resource and set its value with the length of the collection and use that one in the maximum selection section. Attached are the screenshots.

Salesforce Fact #664 | Case accountId & contactId auto populate in community

When creating a case from a community user, the ContactId is auto-populated with the contact associated with the logged in community user. The AccountId field is also auto-populated with the related account record.

Salesforce Fact #663 | Bulk API job states

Below are the Bulk API Job states: 1. Open: The job has been created. 2. UploadComplete: The data has been uploaded to the job. 3. InProgress: The job is being processed by Salesforce. 4. Aborted: The job has been aborted. 5. JobComplete: The job has been processed by Salesforce. 6. Failed: Some records in the job got failed. Reference:  https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/get_job_info.htm

Salesforce Fact #662 | Undelete multiple records using screen flow datatable

Image
We can make use of the datatable type in screenflow to undelete multiple selected records. Suppose, we want to show the records deleted by the user today and provide a way to undelete multiple records. We can create an apex class with an invocable method while performs the undeleted on the selected record Ids. Attached are the screenshots.

Salesforce Fact #661 | Close related opportunities from screen flow

Image
We can create a screen flow to mark the related opportunities as closed won/lost from the account detail page. Attached are the screenshots.

Salesforce Fact #660 | renderStoredEmailTemplate

While sending email related to VF email template from apex code, the translation might not work correctly using Messaging.SingleEmailMessage. The email template contains multiple custom labels and translation are also added accordingly. There is a method renderStoredEmailTemplate(templateId, WhoId, WhatId) of Messaging class which can render and translate the email data correctly corresponding to the intended language. Calling this method consumes one SOQL query count. Reference:  https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_classes_email_outbound_messaging.htm#apex_System_messaging_renderStoredEmailTemplate

Salesforce Fact #659 | RelatedToId on EmailMessage object

Image
The RelatedToId field on EmailMessage object represents nonhuman objects such as Accounts, Opportunities, Campaigns etc. So, whenever we send out an email from a lead or contact record page, new row gets created but the RelatedToId field is blank for that record. Reference:  https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_emailmessage.htm Attached is the screenshot.

Salesforce Fact #658 | Undelete not possible

Image
In Salesforce, not all the entity types can be undeleted. If we try to undelete a deleted instance which is not supported, the below error is encountered: 'Entity type is not undeletable' For example, if we try to undelete a CollaborationGroup it shows the same error. Attached is the screenshot.

Salesforce Fact #657 | RecordTypeLocalization

Image
There is an object RecordTypeLocalization which stores the translated value of record type label when translation workbench is enabled in the org. Reference:  https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_recordtypelocalization.htm Attached are example screenshots.

Salesforce Fact #656 | Inserting data into SetupEntityAccess

Similar to retrieving data, we can insert rows using apex as well in SetupEntityAccess object for custom permission. Example code: SetupEntityAccess sea = new SetupEntityAccess(); sea.ParentId='0PS6F0000057tXt'; // this is the permission set Id sea.SetupEntityId='0CP6F000000XkviWAC'; // this is the custom permission Id insert sea; Note: If an attempt is made to insert row for an already existing combination, the error 'DUPLICATE_VALUE, duplicate value found:' is shown.

Salesforce Fact #655 | SetupAuditTrail

The SetupAuditTrail object stores all the metadata level changes in the org made by admin or other users. This stores the data for the last 180 days. This is the same data which we get to see from the 'View Setup Audit Trail' option from setup. Note: This object is not supported in VF standard controller. Also, it does not support aggregate queries. Reference:  https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_setupaudittrail.htm

Salesforce Fact #654 | Custom permission assignments

Image
Suppose we have a scenario where we need to find out a particular custom permission is assigned to which all permission sets. There is an object called SetupEntityAccess which is helpful in this case to get the details. In this example, we are getting the details for a custom permission named ' Test_Custom_Permission'. SOQL used ->  SELECT Id, Parent.name, SetupEntityId, SetupEntityType, SystemModstamp FROM SetupEntityAccess  WHERE parent.isownedbyprofile=False AND SetupEntityId IN (SELECT Id FROM CustomPermission  WHERE DeveloperName='Test_Custom_Permission') Attached is the screenshot.

Salesforce Fact #653 | Reset value in combobox

Image
Suppose we have a scenario in LWC where we need to reset the value of the combobox on button click. We can achieve this using template.querySelector(). Attached are the screenshots.

Salesforce Fact #652 | OrgLimit Class

There is a class name OrgLimit which provides the details about the various limits of the salesforce org. It has four methods: getName(), getValue(), getLimit() & toString(). Reference:  https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_System_OrgLimit.htm

Salesforce Fact #651 | IN operator with Day_Only()

We can use IN operator to put filter on multiple dates while using Day_Only function. For example, the below SOQL returns the accounts which were created on 27th and 28th Jan of 2023. SELECT Id, Name, CreatedDate FROM Account WHERE Day_Only(CreatedDate) IN (2023-01-27, 2023-01-28) The same works perfectly with bind variables as well: Date d1 = Date.parse('01/27/2023'); Date d2 = Date.parse('01/28/2023'); List<Account> accList = [SELECT Id, Name, CreatedDate FROM Account WHERE Day_Only(CreatedDate) IN (:d1, :d2)];