+ Start a Discussion
LALALALALALA 

trigger to create quote problem, Please

Hi everybody, I have a problem on my project, because I am new, so please help me, thank you a lot:)

My problem:

I need automatically create a quote on opportyunity by trigger, and I need use some data from custom object which are from OrderFromWeb__c and Orders__c. So, once I create an order__c, will trigger an new opportunity and then according to this opportunity to create an quote.

could any one can give me a example code for this, thank you:)
KaranrajKaranraj
Hi - Using a lighning process builder you can able to do this without writing a code.

1. Create a Lighning process builder for ht Order whenever record is created then selecte the action as 'Create record' and create the Opportunity record.
2. Create a another process builder for the object Opportunity with same criteria and create your quote object in the action. 

To know, more about lighning builder take a look into this Trailhead module - https://developer.salesforce.com/trailhead/force_com_admin_intermediate/business_process_automation/process_builder
Jayant JadhavJayant Jadhav
trigger CreatingOppAndQuote on Order__c(After insert)
{
   if(Trigger.isAfter)
{
    List<Opportunity> oppCreatelist=new List<Opportunity>();
    List<Quote> quoteCreatelist=new List<Quote>();
    for(ChildObj__c c: Trigger.new)
    {
        //Create opportunity based on your requirement i.e assign values form your custom object to opportumnity
       //You can use your OrderFromWeb__c data to create opportunity.
        Opportunity opp=new Opportunity();
        opp.name=c.name;
        opp.StageName='Prospecting'; 
        opp.CloseDate=date.today().addDays(30);
        oppCreatelist.add(opp);
        
        //Create opportunity based on your requirement i.e assign values form your custom object to opportumnity
        Quote qt=new Quote();
        qt.name=c.name;
        quoteCreatelist.add(qt);
    }
    if(!oppCreatelist.isEmpty())
    insert oppCreatelist;
   
    
    Integer numberOfRecords=oppCreatelist.size();
    // Assign opportunity to Quote
    for(Integer i=0; i<numberOfRecords;i++)
    {  
        quoteCreatelist[i].Opportunityid=oppCreatelist[i].id;        
    }
    
    if(!quoteCreatelist.isEmpty())
    insert quoteCreatelist;
}
}

Let me know if this works for you.