
Learn All About IDs in Salesforce
Ids in Salesforce
Hello everyone, In our previous blog we learned about Salesforce in career growth. In this blog, we are about to find out about “IDs in Salesforce”.
External ID in Salesforce.
- External id is a unique record identifier from a system outside of Salesforce. In the case of importing data by data import wizard, the system can figure out duplicate records with the help of their external Id's.
- Creating a field and set it as an external ID field:
- Setup >> Object Manager >> Select any object.
Take the Contact object as an example.
Creating a Custom External ID Field to Contact:
- Setup >> Object Manager >> Contact >> Custom Fields & Relationships section, click New.
- Selecting a data type for the fieldfrom the dataType list
- In this case, select Text then click Next.
- Enter the details for the fields, Field Label, Length, Field Name, Description.
We can also check whether or not values are case sensitive. If we need values to be case-sensitive, then click on the option check don't allow duplicate values box, and then select Treat “ABC” and “abc” as different values (case sensitive).
- Check the External ID box, and click on Next.
- Setting the field-level security >> Next >> Save.
Don't forget to check out: Create and Insert Record in LWC Without Using record-edit-form | Salesforce Developer Guide
Field marked as External ID is created.
- For better understanding:
If any application that has data of employees (like empId, name, designation etc.) is now linking with Salesforce so after they both linked together and application's data imported to Salesforce so at that time the empId of employees in the existing application is considered as an external Id for Salesforce.
Record ID
Each record within the Salesforce.com system features a unique ID field assigned to that which is understood as Record ID. it is system generated and can't be edited or deleted. it is generated whenever a replacement record is inserted into the application.
Record Id uniquely identifies each record in Salesforce. Salesforce record Id can either be 15 or 18 digit.
15 digit Salesforce record id is case sensitive and 18 digit Salesforce record id is case insensitive. Every record in Salesforce is provided with a unique record Id in every Salesforce organization to uniquely identify them.
- The 15 digit case-sensitive version of record ID is referenced in the UI and also visible in the browser.
- The 18 digit case-insensitive version of record IDs which is referenced through the API format.
Below is the process of how we can convert the 15 digit record ID to 18 digit
Visualforce Code:
<apex:page controller="IdConvert"> <apex:form > <apex:pageBlock > <apex:pageMessages id="showmsg"></apex:pageMessages> <apex:pageBlockButtons > <apex:commandButton value="Convert" action="{!convert}"/> </apex:pageBlockButtons> <apex:pageBlockSection > <apex:inputText value="{!inputId}" label="Input Id:"/> <apex:outPutText value="{!outputId}" label="Output Id:"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Check out another amazing blog by Narendra here: Power of Search in Salesforce
Apex Code:
public with sharing class IdConvert{ public String inputId{get;set;} public String outputId{get;set;} public PageReference convert(){ outputId = convertId(inputId); return null; } String convertId(String inputId){ string suffix = ''; integer flags; try{ for (integer i = 0; i < 3; i++) { flags = 0; for (integer j = 0; j < 5; j++) { string c = inputId.substring(i * 5 + j,i * 5 + j + 1); if (c.toUpperCase().equals(c) && c >= 'A' && c <= 'Z') { flags = flags + (1 << j); } } if (flags <= 25) { suffix += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.substring(flags,flags+1); }else{ suffix += '012345'.substring(flags - 26, flags-25); } } } catch(Exception exc){ ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please enter Valid 15 digit Id')); } String outputId = inputId+suffix; return outputId; } }
Responses