Discover Comprehensive Insights Into IDs In Salesforce

Identifiers in Salesforce

Hey there, in our last blog, we delved into Salesforce’s impact on career progression. Today, let’s explore the realm of “Salesforce IDs”.

External Identifier in Salesforce.

  • An external ID is a distinct record identifier originating from a system external to Salesforce. When importing data via the data import wizard, the system can identify duplicate records using their external IDs.
  • To establish a field and designate it as an external ID:
  • Navigate to Setup >> Object Manager >> Choose any object.

Consider the Contact object as an example.

Establishing a Personalized External ID Field for Contacts:

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

Field marked as External ID is created.

  • For better understanding:

When integrating an application containing employee data (such as empId, name, designation, etc.) with Salesforce, the linkage results in the application’s data being imported into Salesforce. During this process, the empId from the existing application becomes an external identifier 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>

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;
    }
}