function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
cha runcha run 

how to get Object ID

Guys,

 

 

I am using a Command link where user will be guided to Record creatiion on an object.

 

When I try this for packaging, the object ID of my sandbox and other sandbox differ.

 

How to manage this?

Best Answer chosen by Admin (Salesforce Developers) 
cha runcha run

 

Guys,
Thanks for your replies.
Got the solution for it.
Schema.Describesobjectresult result = Schema.Sobjecttype.SMS_Gateway__C;
string objId = result.getKeyPrefix()+ '/e';


 

The above code gets the object ID.

All Answers

Ankit AroraAnkit Arora

Hi Charun,

 

This is obvious, we can not hardcode the ID because it is organization specific. To solve this you can create a custom setting for it and put your hardcode ids in it, so that after package you just have to change the IDs in custom setting and use those custom setting values in your code.

 

Let me know if it still not resolves your problem.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

Bhawani SharmaBhawani Sharma

How you are using commandLink to create the record on object level?

Are you building any URL or it's in code part ?

Ankit AroraAnkit Arora

Bhawani,

 

I suppose the link is on the visualforce page from where user will be redirected to the creation of object record.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

cha runcha run

 

Guys,
Thanks for your replies.
Got the solution for it.
Schema.Describesobjectresult result = Schema.Sobjecttype.SMS_Gateway__C;
string objId = result.getKeyPrefix()+ '/e';


 

The above code gets the object ID.

This was selected as the best answer