Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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 (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 at 12:02

1 Answer 1

up vote 4 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 at 11:42
    
If you're looking for the default setting, replace :profileId with User.getOrganizationId() –  James Loghry Jul 1 at 13:20
    
thanks James. Will update my answer with your comment if you don't mind. –  guy Jul 2 at 8:37
    
Humble Correction - It is 'UserInfo.getOrganizationId()'. –  Dharshni Jul 14 at 15:04
    
Of course, using a query means you'll be using a governor limit, so use it sparingly. –  sfdcfox Jul 15 at 5:52

Your Answer

 
discard

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.