7

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.

  • Have a look at using the workbench (workbench.developerforce.com) 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 developer.salesforce.com/page/Workbench – Richard Durrant Jul 1 '14 at 12:02
9

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()

  • 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 Clairbois Jul 2 '14 at 8:37
  • 1
    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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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