Skip to content

Instantly share code, notes, and snippets.

@dhoechst
Created November 18, 2021 17:50
Show Gist options
  • Save dhoechst/4d465f5a1b59856a4c2b5ca1eba28ec7 to your computer and use it in GitHub Desktop.
Save dhoechst/4d465f5a1b59856a4c2b5ca1eba28ec7 to your computer and use it in GitHub Desktop.
Salesforce CPQ Submit Quote Page that prevents multiple submits
public with sharing class QuoteApprovalController {
private SBQQ__Quote__c sbQuote;
ApexPages.StandardController qtController;
public SBAA__Approval__c[] approvals {
get {
if (approvals == null) {
approvals = SBAA.ApprovalAPI.preview(
sbQuote.Id,
SBAA__Approval__c.Quote__c
);
}
return approvals;
}
set;
}
public Boolean isReadyForApproval { get; set; }
public QuoteApprovalController(ApexPages.StandardController stdController) {
this.qtController = stdController;
this.sbQuote = (SBQQ__Quote__c) stdController.getRecord();
// you can do some checks here to make sure all prerequisites are met to submit
isReadyForApproval = true;
}
public PageReference onSubmit() {
if (sbQuote != null) {
if (qtController.save() == null) {
return null;
}
SBAA.ApprovalAPI.submit(sbQuote.Id, SBAA__Approval__c.Quote__c);
}
PageReference pr = qtController.view();
pr.setRedirect(true);
return pr;
}
public PageReference onRecall() {
if (sbQuote != null) {
SBAA.ApprovalAPI.recall(sbQuote.Id, SBAA__Approval__c.Quote__c);
}
return qtController.view();
}
}
<apex:page standardController="SBQQ__Quote__c" extensions="QuoteApprovalController" title="Submit Quote for Approval" lightningStylesheets="true">
<apex:outputPanel id="messages">
<apex:pageMessages />
</apex:outputPanel>
<apex:form >
<apex:pageBlock title="Submit Quote for Approval">
<apex:pageBlockSection columns="1" collapsible="false" title="Quote Information" id="quoteInfo">
<apex:outputField value="{!SBQQ__Quote__c.Name}" />
</apex:pageBlockSection>
<apex:pageBlockButtons location="bottom">
<apex:actionStatus id="saveStatus">
<apex:facet name="stop">
<apex:commandButton value="Submit" action="{!onSubmit}" rendered="{!isReadyForApproval}" rerender="messages" status="saveStatus"
/>
</apex:facet>
<apex:facet name="start">
<apex:commandButton value="Saving..." status="saveStatus" disabled="true" rerender="messages" />
</apex:facet>
</apex:actionStatus>
<apex:commandButton value="Cancel" action="{!cancel}" immediate="true" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
<apex:pageBlock title="Approval Preview">
<sbaa:approvalPreview approvals="{!approvals}" />
</apex:pageBlock>
</apex:page>
@dhoechst
Copy link
Author

Hard to say exactly. Why are you creating approval records? I'd think you might need Approval Rule records. You might also be missing some fields when you create your quote.

@DanielRbCt
Copy link

I'm not creating it, I'm updating some fields in the records that were created, you who specialize in Advanced Approvals would have some material to send me, because salesforce's documentation is very weak about the resource

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment