You need to sign in to do that
Don't have an account?
Enry
Get object Id
Hi,
I have a doubt.
When i have to use an id which is the best way to put it in a variable.
user u=[Select id,name from user where... limit 1 ]; post.CreatedById=u.id;
or
post.CreatedById='005E0000003XNVp';
are there other way?
Which is the best practise?
Thanks in advantage.
BR
You should never really hard code in an Id in the code because if you ever change / migrate to a new sandbox that users' Id will change, and then you will have to change it in the code everytime you hardcoded it in.
Thanks for the reply!
okkay hard coding an ID is bad.
Actually i'm doing:
But make a query for me is also a bad solution.
If you after change the name of the user(the same for other resources or objects) , get id won't work again.
This is a problem for me ever, i have this doubt everytime i'm getting an id from an object,resource..
the best solution is use custom setting?
Another solution that i 've found is use the custom labels.
Do you know if is also a good solution?
Thank you very much!