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
Mandy_in_MNMandy_in_MN 

How to Synch a Quote using an Apex Trigger?

Hi,

 

My company needs at least one Quote on every Opportunity we sell.  It would be a big advantage to us to have a Quote be automatically created and synched when the user creates an Opportunity.  We really want to get the Quote Number right away.  The majority of our Opportunities only need one quote, and products can be added later.  

 

Here's how I think we could approach it:

1. Automatically create a Quote for every new Opportunity
2. Automatically Synch that Quote to the Opportunity
3. Add a formula field to the Opportunity to display the Synched Quote Number 

I have Steps 1 and 3 working in my Sandbox, thanks to a previous post, but I'm getting stuck on Step 2.  

 

Automatically Creating a Quote when a New Opportunity is created.  This part is working:

trigger QuoteCreator on Opportunity (after insert) {
for (Opportunity o : Trigger.new) {
Quote q = new Quote();
q.name = 'P-' + o.name;
q.opportunityId = o.id;
insert q;
}
}

 

Attempt to Automatically synch Quote by adding one more line "q.issynching = true."  This part is NOT working :

trigger QuoteCreator on Opportunity (after insert) {
for (Opportunity o : Trigger.new) {
Quote q = new Quote();
q.name = 'P-' + o.name;
q.opportunityId = o.id;
q.issynching = true;
insert q;
}
}

 

I'm getting a message that tells me issynching for SObject Quote is an invalid field.  

 

Has anyone run into this before?  Is it even possible to set a Quote to Synch using Apex?  

 

Thanks.

Mandy

 

SFFSFF

I'm pretty sure - but not positive - that if you update the Opportunity.SyncedQuoteId field with the Quote ID, it will consider that a sync.

 

Hope this helps,