Posts

Showing posts from January, 2023

How to enable Administrator to log in as any user in Salesforce

 Administrator have option to login into the account of any user without entering their username/password. In Order to allow Administrator to login as any user, we need to make changes in below settings: We need to enable "Administrators Can Log in as Any User" setting. To do this, follow below steps: Setup > Login Access Policies > Check Administrators Can Log in as Any User checkbox. By enabling above setting, Administrator will be able to login into the account of any user but when they click logout, whole session will be destroyed. Means Administrator will be logged out from his/her session as well. If we want to keep Adminstrator session alive when Administrator logged out from user account, we need to uncheck the "Force relogin after Login-As-User" checkbox. To change this setting, we need to follow below steps: Setup > Session settings > Uncheck Force relogin after Login-As-User  checkbox.

Wrapper Class In Apex

 A wrapper is a class, an abstract data type that contains different objects or collections of objects as its members.  A wrapper class is a custom object defined by the programmer wherein he defines the wrapper class properties. Its similar to the custom object of Salesforce. In custom object of Salesforce, we have different fields of different data types. Similarly wrapper class is a custom class which has different data types or properties as per requirement. We can wrap different object types or any other data types in a wrapper class. Its instances could be different data types: Primitive Collections sObjects Benefits of a Wrapper Class: Converting the JSON string into an object (and vice versa) is easily achieved using Wrapper Class. Wrapper Class helps to combine different types(datatype) of data. For example:  public class AccountContactController{     public static AccountContactListWrapper getAccountWithContacts(String accId){      ...

Formula Field In Salesforce

 Formula fields are custom READ-ONLY fields that derive their value from a formula expression you define. It calculates the latest value when it is viewed or when any of the source fields changes. We can use formula fields in Reports and SOQL queries. Below are some characteristics of the Formula field in Salesforce: Formula fields are READ-ONLY fields. We can not change/update their values at own. Formula fields derive/calculate the values using the Formula expression. When the source field changes, the value of the formula field is automatically updated. Formula field return type: We can create formula fields of only below mentioned returned type: Checkbox Currency Date Date/Time Number Percent Text Time Note: We can use one formula field in calculation other formula fields. Limit: The formula field can contain up to 3900 characters(including spaces, and comments). If we need more characters then we can divide the formula in different parts and can create separate formula field...

Salesforce Record Id

 Record Id is used to identify the record uniquely in a Salesforce Org. There are 2 types of record Id in Salesforce: 15 digit 18 digit 15-digit record Id is case-sensitive where as 18-digit record Id is case-insensitive .  15-digit record Id is referenced in UI and also visible in browser. It is true in classic but in lightning 18 digit record Id is being used in UI and also visible in browser. 18-digit record Id is referenced through the API. The last 3 digit of the 18-digit record Id is a check sum of the capitalization of the first 15 characters. A 15-digit record Id can be converted into 18-digit record Id using CASESAFEID() function. To convert 18-digit record Id into 15-digit record Id, simply remove last 3 digits from 18-digit record Id. Why we need 18-digit record Id when there was 15-digit record Id: Apex is a case-insensitive language. As 15 digit record Id is case-sensitive therefore we can not use it directly in Apex code. Therefore earlier in classic we were con...

Salesforce External ID

 An External Id is a custom field that has "External Id" attribute checked. Its used to contain unique record identifiers from a system outside of Salesforce. Salesforce allows us to mark only custom field with data type Text , Number or Email as External Id. Note: External Id is not case-sensitive.  Considerations: External Id is an attribute that can be added to a custom field to indicate that it should be indexed and treated as an Id. Its a user-defined cross-referenced field. It can be created for custom field type(Text, Number and Email only). Each object can have up to 25 External Ids. Benefits:  It helps improve report and API SOQL performance.  It can be used with UPSERT DML operation to seamlessly integrate apps with other system. No need to know Salesforce Record Id to load data. Very convenient for data integrations and migrations. The import wizard will detect existing records in Salesforce that have the same External Id. It becomes searchable in the s...

Salesforce Data Import

Data can be easily imported into Salesforce using various tools. Below are the two main tools provided by salesforce to import data: Data import wizard Data loader Data Import wizard: Its in-browser tool provided by salesforce. In browser means its available in each Salesforce org and we need not to install any software to use it. Using Data Import wizard, we can perform only below 3 operations: Insert: It simply creates new records in Salesforce org. Update: It modify existing records in Salesforce org with the help of record Id or external Id. Upsert: Its combination of insert and update operation. It modifies the existing records and if record doesn't exists in salesforce org, it creates new record. Limitations of Data Import Wizard: There are few limitations of Data Import Wizard: It can import up to 50,000 records at a time. We can import data in some standard objects such as Account, Contact, Lead, Solutions, Campaign Members, Person Account(If enabled), and all custom obje...

Parent-child and Child-Parent SOQL in Salesforce Apex

Parent-Child SOQL:  In order to fetch child object data while querying on parent object, we need to write subquery as illustrated below: Scenario: Suppose we have two objects: Student(Api Name: Student__c) Student Address(Api Name: Student_Address__c) Student is parent object and Student Address is child object. SOQL: In order to fetch child object data with parent object using parent-child query, first we need to check for " Child Relationship Name " on child object and use it in subquery. For above mentioned scenario, "Child Relationship Name" on Student Address is " Student_Addresses ". As Student Address is a custom object therefore we will use "__r" with it's "Child Relationship Name" in sub query. So the SOQL will be as below: Select Name , ( Select Id  from Student_Addresses__r ) from Student__c; If child object is a standard object then we need not to use "__r" with "Child Relationship Name" in sub quer...