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
mustapha L 1mustapha L 1 

SyncedQuoteId read only field ?

Hi there,

my project is the next i'm looking to AUTOmatically SYNC a quote (to its opportunity) as long as the status of the Quote is "Accepted"
i did Trigger for that which "in therorie" should answer to the need, but for unknown reason it seem that the fireld is "SyncedQuoteId " is readOnly:

trigger QuoteAutoSync on Quote (before update) {
    for (Quote q : Trigger.New) {
        //check if the Status of the quote is Accpted, if yes the quote is sync to opportunity
        if (q.Status == 'Accepted'){           
            Opportunity opp = new Opportunity();
            opp.id=q.OpportunityId;
            opp.SyncedQuoteId = q.Id;
            update opp;
        }
    }
}
is this something that we can change or it is a stuff fixed once for all by SalesForce ?

Thnaks
 
Best Answer chosen by mustapha L 1
Krishna SambarajuKrishna Sambaraju
You can call a future method and update the opportunity as below.
trigger SyncToOpp on Quote (after update) {
    Set<Id> qIds = new Set<Id>();
    for (Quote q : Trigger.new)
    {
        if (q.Status == 'Accepted')
        {
            qIds.add(q.Id);
        }
    }
    if (qIds.size() > 0 && !System.isFuture())
    {
        SyncQuoteWithOpportunity.SyncQuote(qIds);
    }

}
public class SyncQuoteWithOpportunity{
    @future
    public static void SyncQuote(Set<Id> quoteIds)
    {
        List<Quote> quotes = [select Id, OpportunityId from Quote where Id in :quoteIds];
        List<Opportunity> opps = new List<Opportunity>();
        for (Quote q : quotes)
        {
            Opportunity opp = new Opportunity();
            opp.Id = q.OpportunityId;
            opp.SyncedQuoteId = q.Id;
            opps.add(opp);
        }
        update opps;
    }
}

Hope this helps.
 

All Answers

Krishna SambarajuKrishna Sambaraju
SyncedQuoteId is readonly if you are using it in trigger. Please refer the following.
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_opportunity.htm
Krishna SambarajuKrishna Sambaraju
You can call a future method and update the opportunity as below.
trigger SyncToOpp on Quote (after update) {
    Set<Id> qIds = new Set<Id>();
    for (Quote q : Trigger.new)
    {
        if (q.Status == 'Accepted')
        {
            qIds.add(q.Id);
        }
    }
    if (qIds.size() > 0 && !System.isFuture())
    {
        SyncQuoteWithOpportunity.SyncQuote(qIds);
    }

}
public class SyncQuoteWithOpportunity{
    @future
    public static void SyncQuote(Set<Id> quoteIds)
    {
        List<Quote> quotes = [select Id, OpportunityId from Quote where Id in :quoteIds];
        List<Opportunity> opps = new List<Opportunity>();
        for (Quote q : quotes)
        {
            Opportunity opp = new Opportunity();
            opp.Id = q.OpportunityId;
            opp.SyncedQuoteId = q.Id;
            opps.add(opp);
        }
        update opps;
    }
}

Hope this helps.
 
This was selected as the best answer
mustapha L 1mustapha L 1
I'm Totally new on SalesForce and also on DEV. i do not understand at all what you did, Buuut It seems to work fine !
MANY THANKS , it exactly does what i need.
i will have to work to make some "security" to ensure our sale do not flag more than 1 quote as accepted to avoid any unexpected state now.
Once again many thanks