8

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.

1
  • 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 Commented Jul 1, 2014 at 12:02

1 Answer 1

11

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

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

You must log in to answer this question.

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