Is there any way, which we can insert our own values in the record Id field in a salesforce Object?

I know, when we insert any new record, the record Id is automatically assigned by the system.

But, can we Insert our own defined values in the Record Id column in a salesforce Object by passing from the external method caller such as anonymous execute window? Just like normally we insert other fields? If so how? Some one please explain..

3 Answers 3


No, Record Id is system generated and cannot be edited or deleted. It is generated every time a new record is inserted into the application.

You can read more about Id here.


Record Id's are autogenerated and there are good reasons for it. ID's look like a random generated string but there is much more information in that like pod number and characters to make sure it is case insensitive, you can more details here and here.

While you can program some logic, there is a high changes that there will be collision within your own org or within the POD which will violate the rules of Salesforce DB table where the records are saved should you generate it by yourselves. You can see how Salesforce stores data here

In case you want to generate something yourselves, you can simply create a field and mark it external and use it to query or update data.


For unit testing, there is nothing to stop you from mocking records with a generated Id providing you don't actually try and insert those records.

Is this for tests or in general?

  • The record Id values need to be passed as input from the method caller say execute anonymous window to actually check if those records exist in the database, and if they, will be returned as duplicates, if not should be inserted as new records. Record Id column is the only unique key here in this scenario, that can be used to check the existence of the records. In this case, I am struck how can we pass the record Ids of some non existing records and insert them as new records inside the salesforce object. May 24, 2021 at 5:11
  • You'd usually do this via an upsert and a field marked as an external id: Using the upsert operation, you can either insert or update an existing record in one call. To determine whether a record already exists, the upsert statement or Database method uses the record’s ID as the key to match records, a custom external ID field, or a standard field with the idLookup attribute set to true.
    – Dan Beer
    May 25, 2021 at 8:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .