function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Peter Martensen 8Peter Martensen 8 

Can someone help add "after update" to this trigger?

I need this trigger to fire after the record is edited also.  Can someone add "after update" to it?
Thanks
trigger QuoteTrigger on SBQQ__Quote__c (before insert, before update) {

    if(Trigger.isBefore) {
        QuoteTriggerHandler.setSignatureURL(Trigger.new);
    }
}

 
GovindarajGovindaraj
Hi Peter,

Please try below code,
trigger QuoteTrigger on SBQQ__Quote__c (before insert, before update, after update) {
if(Trigger.isBefore) {
   QuoteTriggerHandler.setSignatureURL(Trigger.new);
}
if (trigger.isAfter) {
    if(trigger.isUpdate) {
          //Call the trigger handler
    }
}
Please let us know if this helps.

Thanks,
Govindaraj.S
Raj VakatiRaj Vakati
After the update, the ready will be read-only so make sure you will not get any exception ..  What is the logic in QuoteTriggerHandler ? 

 
trigger QuoteTrigger on SBQQ__Quote__c (before insert, before update, after update) {
if(Trigger.isBefore ) {
   QuoteTriggerHandler.setSignatureURL(Trigger.new);
}
if (trigger.isAfter) {
    if(trigger.isUpdate) {
          //Call the trigger handler
    }
}

 
Peter Martensen 8Peter Martensen 8
@Raj,
You are right.  The record becomes Read-Only and throws and exception.  The result of the Apex Class is the QuoteTriggerHandler attaches a picture of a signature based on a User on the record to a CPQ Quote.  Signature__c is a picklist of users.  This Class finds the chosen users signature file and saves the link to the Signature_Location__c field.  The CPQ Quote pulls the picture of the signature and places it on the quote pdf.  Very often, the Quote does not have the signature on it.  I think that is because the user did not choose the Proposal Writer before saving the record the first time.  Is there a way to get this trigger to fire every time the record is edited?
public without sharing class QuoteTriggerHandler {

    public static void setSignatureURL(List<SBQQ__Quote__c> scope) {

        List<String> names = new List<String>();

        for(SBQQ__Quote__c quote : scope) {
            if(quote.Signature__c != null) {
                names.add(quote.Signature__c);
            }
        }

        if(names.size() > 0) {
            List<Document> docs = [SELECT Id, Name FROM Document WHERE Name IN :names];
            Map<String, String> nameMap = new Map<String, String>();

            for(Document d : docs) {
                nameMap.put(d.Name, d.Id);
            }

            for(SBQQ__Quote__c quote :scope) {
                if(quote.Signature__c != null) {
                    if(nameMap.get(quote.Signature__c) != null) {
                        quote.Signature_Location__c =  nameMap.get(quote.Signature__c);
                        String instance = System.URL.getSalesforceBaseUrl().getHost();
                        quote.Instance__c = instance.split('.salesforce')[0];
                        quote.OrgId__c = UserInfo.getOrganizationId();
                    }
                }
            }
        }
    }
}