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
NeerajaNeeraja 

How do I write a trigger that would automatically create an order whenever a quote get accepted? Thanks Neeraja

salesforce mesalesforce me
Hi Neeraja check it once...
 
trigger test1 on Order__c (after insert)

{

Order__c to=trigger.new[0];

Quote q=[select id from Quote where id=:to.Quote__c];

QuoteLineItem ql=[select id,...,....,.. from QuoteLineItem where Quote=:q.id];

 

for(QuoteLineItem qli:ql)

{

OrderLineItem__c lm=new OrderLineItem__c();

lm.Email__c=qli.Email;

.....

.....

.....

 

lm.TestObject__c=qli.id;

insert lm;

}

 
salesforce mesalesforce me
check this one also...
trigger qlitem on QuoteLineItem (after insert, after update) {
        
        List<opportunity> opl=new List<opportunity>();
        
        public static double total=0;
        List<quotelineitem> qlil=new List<quotelineitem>();
        Quote Q=new Quote();
        Opportunity opp=new Opportunity();
        
        for(quotelineitem qli:trigger.new){
            //qlil.add(qli);
        
        Q= [Select id,opportunityid ,grandtotal,totalprice,primary__c from quote where id=:qli.quoteid];
        
        opp=[Select id, amount from Opportunity where id=:q.opportunityid];
        
            
        }
        for(integer i=0;i<qlil.size();i++){
             total=total+qlil[i].TotalPrice;
        }
        if(q.primary__c){
              
                //This logic is used for updating the amount of opportunity  with quote total price
                Opp.amount=q.totalprice+total ;
                
            }
            opl.add(opp);
            
            update opl;
        
        
        
}

 
NeerajaNeeraja
Thank you so much. I will try and let you know. If I have any queries I will get back to you.