Tag Archives: External ID

External ID in Salesforce

An External Id is a custom field that has enable the “External ID” attribute. This field is usually references an ID from another (external) system. When a field is marked as external Id, the field will be automatically indexed.

Note: External Id is not case-sensitive – for example, “XYZ” will be matched with “xyz”. if the custom field has enable the “Unique” attribute and the case-sensitive option for that attribute is selected, uppercase and lowercase letters will not be considered identical.


  • 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.
  • It is a user-defined cross-referenced field.
  • It can be created for custom field type (Text, Number or Email ONLY).
  • Each object can have up to 7 external Ids (as of Spring ’15).
  • Configure UPSERT action to traverse object relationships defined in Salesforce, but use External Id’s from legacy system to discover Salesforce record ID’s.


  • It helps improve Report and API SOQL performance.
  • It can be used with UPSERT DML operation to seamlessly integrate apps with other systems.
  • No need to know Salesforce record Id’s 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 sidebar search.

Example: If you have an Oracle Financials system that they will be linking with Salesforce, it may be easier for them to be able to refer to the Oracle ID of account records from within Salesforce. So, You can create an external ID in Salesforce and you can load the Oracle ID into that field for each account. You can then refer to that ID field, rather than the Salesforce id.

Create Parent And Child Record In A Single DML Statement Using External ID

Sample Code

//Parent Account
Account acc = new Account();
acc.Name = 'Salesforce';
acc.ExternalID__c = '12333';//External Id

//Child Contact
Contact con = new Contact();
con.FirstName = 'John';
con.LastName = 'Doe';
con.Account = new Account(ExternalID__c = '12333');

List<Database.SaveResult> results = Database.Insert(new SObject[] {acc, con});

for (Integer i = 0; i < results.size(); i++) {
    if (results[i].isSuccess()) {
        System.debug('Successfully Created record ID: '+ results[i].getId());