Quotes don’t automatically create opportunities after creation. To enable automatic
opportunity generation, create a trigger that creates an opportunity after Salesforce CPQ saves a
customer site quote. (Salesforce CPQ Managed Package)
Required Editions
Available in: Salesforce CPQ Summer ’17 and later
Here’s an example of a trigger you can use to create an opportunity in response to the saving
of a customer quote.
Example
trigger AfterUpdateCreateOppty on SBQQ__Quote__c (after update) {
for(SBQQ__Quote__c q : trigger.new){
if(q.SBQQ__Status__c == 'Approved' && trigger.oldMap.get(q.Id).SBQQ__Status__c != 'Approved'){
Id accountId = [SELECT SBQQ__Account__c FROM SBQQ__Quote__c WHERE ID=:q.Id].get(0).AccountId;
Opportunity o = new Opportunity(Name=q.Name+' '+'Opportunity', AccountId= accountID, CloseDate=date.today(), StageName='Qualification', SBQQ__QuotePricebookId__c=q.SBQQ__PricebookId__c);
System.debug('My Name' + o);
Database.Insert(o);
q = [ select id from SBQQ__Quote__c where id = :q.id limit 1];
q.SBQQ__Opportunity2__c = o.Id;
q.SBQQ__Primary__c = True;
q.SBQQ__Account__c = accountID;
Database.Update(q);
Opportunity o2 = [ select id from Opportunity where id = :q.SBQQ__Opportunity2__c limit 1];
o2.StageName='Closed Won';
Database.Update(o2);
}
}
}
Did this article solve your issue?
Let us know so we can improve!
Loading
Salesforce Help | Article
Cookie Consent Manager
General Information
Required Cookies
Functional Cookies
Advertising Cookies
General Information
We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required Cookies
Always Active
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional Cookies
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising Cookies
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.