As a Salesforce system administrator, I recently created a custom report to pull out the IDs of account and contact records from our Salesforce org, but there was an issue fetching the IDs of the records. The IDs of records are generally 18 digits, but the report data only gave 15-digit IDs of records.
As a solution, I created a custom formula field in the objects, from which I have to get the 18-digit IDs using the CASESAFEID() function.
In this Salesforce tutorial, I will explain how to create a formula field to convert a 15-digit ID to an 18-digit one. Then, with that, you can get an 18-digit ID in the Salesforce report.
Get 18 Digit Salesforce ID of Object Records in Report
To obtain the 18-digit Salesforce ID of Object Records in the report, we must first create a formula field for the object to display the record’s 18-digit ID.
After this, we will use this custom field in the report to display the 18-digit ID of the object record.
Create a Formula Field to Get 18-character ID of Records
To create a formula field for the 18-character ID of records in Lightning, navigate to the setup page of Salesforce and follow the steps below.
- On the setup page, click on the Object Manager tab. In the next window, select the account object (or the object for which you need to fetch the ID).

- In the account object, click Fields and Relationships, then click the New button in the next window.

- In this step, select the option Formula from the list of datatypes and click Next.

- In this step, enter the field label for the formula field. Then, in the Formula Return Type, select Text and click on the Next button.

- In the formula editor, enter the formula below and click the Next button.
CASESAFEID(Id)
- Select the visibility for the formula field, and select the profiles to make the field visible for the profiles. The field will be visible for the profiles selected from the Visible column.
After selecting the profiles, click on the Next button.

- In this step, we must select the field’s visibility on the object’s page layouts. In this case, we have created the formula field for the reports so we can choose not to display it on the page layouts.
Uncheck the checkboxes of the page layouts so as not to display the field on the page layouts. After this, click on the Save button.

We have now created the formula field that will return the 18-digit ID of the records in the reports.
Create Report with the 18-digit ID of the Object Record
After creating the above formula field, we will move to the part where we will create a report with the 18-digit ID of the object record. In this example, we will create a report for the account object.
- Navigate to the Reports tab, then click the New Report button.
- Select the Category and Report type for the report, then click on the Start Report button.
- In the report table, apply the required filter to generate the records. To get the 18-digit ID, we will add the formula field we created earlier.
- To add the formula field, search the Columns section and select the created formula field.
- I have added the Account ID and custom fields to display an 18-digit ID. Here, the custom field shows the account records in 18-digit form.

- After this, save and run the report.

The report will run in the next window, displaying the code’s 18-digit ID. Now, we can export the report and use the full ID to update, then import the account records with tools like data import wizard and data loader.

This way, we can create a report with an 18-digit Salesforce ID of the object records in Salesforce Lightning.
Get 18-digit Salesforce Id Using Salesforce Data Loader
If we use tools like Data Loader to export the object record along with the ID field, it will, by default, give the ID field an 18-digit number.
To get the 18-digit object record ID with the data loader, install it on your system and follow the steps below.
- Open the data loader tool, log in with your credentials, and click the Export button.

- In this step, select the object, choose the location of the extracted file, and click the Next button.

- Select the query fields, such as Account Name, Account Owner, and Account ID, and click the Finish button.

- A warning message about the data export operation will appear on the screen. Click the Yes button to proceed.

- After completing the data export operation, you will see the message of successful data export. Here, click the View Extraction button.
In the extracted data, you will see that the object’s record ID is exported in an 18-digit number.

This way, you can use the Salesforce data loader to get an 18-digit record ID for object records in Salesforce Lightning.
Conclusion
In this Salesforce tutorial, we learned how to get and display the 18-digit record ID of the records. In this method, we first created a custom formula field in the object that fetches and displays the 18-digit code using the built-in function CASESAFEID(). Then, we used that field in the report table to display the 18-digit record IDs in the field column.
We also discussed a second way to get the 18-digit record using the Salesforce data loader tool, which can be exported in the same way we export the reports.
You may also like to read:
- Create a Lead Conversion Report in Salesforce
- Create Bucket Fields in Salesforce Reports
- Create Report Sort by Record Count in Salesforce
- Use Add Filter Logic in Salesforce Report
I am Bijay Kumar, the founder of SalesforceFAQs.com. Having over 10 years of experience working in salesforce technologies for clients across the world (Canada, Australia, United States, United Kingdom, New Zealand, etc.). I am a certified salesforce administrator and expert with experience in developing salesforce applications and projects. My goal is to make it easy for people to learn and use salesforce technologies by providing simple and easy-to-understand solutions. Check out the complete profile on About us.