Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Hierarchical Custom Setting that I need to SOQL use a SOQL query for using the current User's Profile.

Currently I'm using the getInstance() method with the User Profile ID to get the custom setting, then I update a field on it. The problem is that it frequently errors with the Unable_to_lock_row error.

I want to try using a SOQL and the FOR UPDATE to try to prevent this error from happening.

share|improve this question
Have a look at using the workbench ( to view the sobjects and develop soql/sosl statements - you'll see your custom setting in there. This way you can see what fields are available and try out difference queries without having to code. More info here – Richard Durrant Jul 1 '14 at 12:02
up vote 7 down vote accepted

Technically, the custom setting is an object just like other custom objects. So you can do the following SOQL query:

SELECT Id, Name FROM Your_Setting__c Where SetupOwnerId = :profileId FOR UPDATE

If you're looking for the default setting, replace :profileId with UserInfo.getOrganizationId()

share|improve this answer
Thank you. What I was missing / didn't know was how to query for the profile id. – Minutiae Jul 1 '14 at 11:42
If you're looking for the default setting, replace :profileId with User.getOrganizationId() – James Loghry Jul 1 '14 at 13:20
thanks James. Will update my answer with your comment if you don't mind. – Guy Jul 2 '14 at 8:37
Humble Correction - It is 'UserInfo.getOrganizationId()'. – Dharshni Jul 14 '14 at 15:04
Of course, using a query means you'll be using a governor limit, so use it sparingly. – sfdcfox Jul 15 '14 at 5:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.