Loading

Direct CPQ users to the Quote Line Editor from the Opportunity in Lightning

Publiseringsdato: Dec 30, 2025
Beskrivelse
Lightning Experience does not facilitate the automatic population of Account information on a CPQ Quote record. However, you have the option to create a custom Apex Class to automate the population of this information
Løsning

1. Create an Apex Class with a name 'quickQuoteController'.

public class quickQuoteController {
    public pageReference genQuote()
    {
        String quoteId;
        // MUST PASS ACCOUNT ID TO URL
        Id acctId = ApexPages.currentPage().getParameters().get('aId');
        
        // IF GENERATING A QUICK QUOTE FROM OPPORTUNITY, PASS OPPORTUNITY ID TO URL
        Id oppId = ApexPages.currentPage().getParameters().get('oId');
        
        // IF NO OPPORTUNITY ID IS PASSED TO THE URL, A NEW OPPORTUNITY IS CREATED
        if(oppId==null){
            Opportunity opp = new Opportunity(AccountID = acctId, stagename = 'Proposal/Price Quote', name = 'New Opportunity', closedate = Date.today());
            Database.insert(opp);
            oppId = opp.id;
        }

        // CREATE NEW QUOTE
        SBQQ__Quote__c q = new SBQQ__Quote__c (SBQQ__Opportunity2__c = oppId, SBQQ__Status__c='Draft', SBQQ__Type__c='Quote', SBQQ__Account__c = acctId, SBQQ__Primary__c = true);
        Database.Insert(q);
        quoteId = q.Id;
        
        // CONSTRUCT URL FOR CPQ CART
        String sfdcBaseURL = URL.getOrgDomainUrl().toExternalForm();        
        //String targetURL = sfdcBaseURL.replace('-c.','-sbqq.') + '/apex/sbqq__sb?scontrolCaching=1&id='+quoteID+'#/product/lookup?qId='+quoteId+'&aId='+acctId;
        String targetURL = sfdcBaseURL.replace('-c.','-sbqq.') + '/apex/sbqq__sb?id='+quoteID;
        return new PageReference(targetURL);
    }
}

2. Create a Visualforce page named quickQuotePage. Ensure the 'Available for Lightning Experience, Lightning Communities, and the mobile app' checkbox is true and enter the following in the Visualforce Markup:
 

<apex:page controller="quickQuoteController" action="{!genQuote}">
</apex:page>


3. Create a custom Button on the Opportunity object with the following Button Link URL:

/apex/quickQuotePage?oId={!Opportunity.Id}&aId={!Opportunity.AccountId}



 

Knowledge-artikkelnummer

000380525

 
Laster
Salesforce Help | Article