Posts

How to install package using npm

 In order to install any package using npm, first we need to make sure that we have already install node in our system. To check node version, run below command in your command prompt: node --version Follow below steps to install and use JS package using npm: 1. Create a folder and inside that folder open git bash and run below command:     npm init     this command will create node_modules folder as well as the package.json file in your folder. 2. Run below command to install specific package:     npm install package-name     such as  npm install mathjs 3. Create a JS such as index.js and put the js code in this file and save it. 4. Execute the JS file using below command:     node index.js

What is mixed DML operation error in apex?

 When we perform DML operation on setup and non-setup objects in a single transaction then we get mixed DML operation error. For example: If we are trying to insert a record in Account object as well as in User object in a single transaction, we will encounter mixed DML error. Have a look at the below code that will produce mixed DML error: Public Class AccountController {          public static void addAccountAndUser() {                    Account acc = new Account();                    acc.Name = 'Vikram Singh Rathore';                    Insert acc;                              Profile p = [SELECT Id FROM Profile WHERE Name = 'Standard User'];                 ...

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...