My users keep hitting a record lock error despite the class being defined as without sharing. My understanding is that without sharing allows locked records to be edited by any user. This class is the only class called for that object on a before insert trigger, and there are no other triggers on that object.

public without sharing class CPQQuoteTriggerHandler {

public static void setNewQuotetoPrimary(List<SBQQ__Quote__c> quotes) {

    for(SBQQ__Quote__c q : quotes) {
        q.SBQQ__Primary__c = true;

public static void falsePrimaryOtherQuotes(List<SBQQ__Quote__c> quotes) {

    Set<Id> parentOppsIdSet = new Set<Id>();
    List<SBQQ__Quote__c> falsePrimaryQuotes = new List<SBQQ__Quote__c>();

    for(SBQQ__Quote__c q : quotes) {

    if(parentOppsIdSet.size() > 0){
        for(SBQQ__Quote__c q : [SELECT Id, SBQQ__Opportunity2__c, SBQQ__Primary__c FROM SBQQ__Quote__c WHERE SBQQ__Opportunity2__c IN: parentOppsIdSet]){
            q.SBQQ__Primary__c = false;

    update falsePrimaryQuotes;

  • You shouldn't need to uncheck the primary on other quotes. CPQ handles that for you. That might be why you are getting record locks. – Daniel Hoechst Mar 12 '19 at 20:14
  • @DanielHoechst Yes but sometimes, we have a Quote that has been previously approved, but not longer the one we want as Primary, and CPQ does not unlock it to false the primary flag if it has been locked. – All about the W Mar 12 '19 at 21:05

Without Sharing only lets you access records they wouldn't normally have access to. Record Locks are still going to be an issue. You should look at the help on sharing in Apex. https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_keywords_sharing.htm


Use of without sharing does not allow you to edit locked records using code. It only opens up the access of records to whoever does not have one.

You cannot edit a locked record either from UI or any code, you can find this documented here, excerpt below (emphasis mine):

When an sObject record is locked, no other client or user is allowed to make updates either through code or the Salesforce user interface.

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.