0

I wonder what should be the recommended best practice regarding object searching.

I have noticed that in case I have more than 1 Salesforce environment (I.E Production & Sandbox) all the objects have the same ID.

Now my APEX code needs to find specific account - I can search it by its name or seems like I can use the ID..

Usually I would rather avoid using the same ID between environment - but using name, well, has risks as well.

So, can I use the ID field, I need to be sure it will always be equal for all the environments.. ?

1 Answer 1

1

Why not store that ID in hierarchical custom settings?

Your apex code will not be hard-coded then. And in case if the Id or Name changes you dont have to deploy code, just update the custom settings value.

String specialAccountId = MySettings__c.getOrgDefaults().AccountId__c ;

This code will be same and safe of hardcode.

Src: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_customsettings.htm

You must log in to answer this question.

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