You need to sign in to do that
Don't have an account?
Santosh S
Trigger for creating new Invoice based on completed Deliverables of Opportunity
need Help for creating a Trigger, which can create new Invoice based on completed Deliverables (Custom Object) of Opportunity (Standard)
1. Deliverable (Detail object with a Master-Detail relationship with Opportunity object)
- Deliverable Name (Name field)
- Opportunity
- Estimate (Currency (16,2))
- Implementation Status (Picklist - Open, Work in Progress, Staged, Completed)
- Invoice (Lookup - to Invoice object)
2. Invoice (Detail object with a Master-Detail relationship with Opportunity object)
- Opportunity
- Invoice Amount (Currency(16,2)) - This should be automatically populated based on the Completed deliverables Read Only
Santosh,
Try below code :-
Trigger insertInvoice on Deliverable__c(before insert,before update){
List<Invoice__c> invoiceList = new List<Invoice__c>();
for(Deliverable__c dc:trigger.new){
if(dc.Implementation_Status__c=='Completed'){
Invoice__c in = new Invoice__c(Name='Test Invoice',Opportunity__c=dc.Opportunity__c,Invoice_Amount__c=dc.Estimate__c ); //Assuming Invoice Amount to be mapped with Estimate
invoiceList.add(in);
}
}
insert invoiceList;
}
All Answers
There can be more than one record of Deliverable under one opportunity, so do you want to check 'Implementation Status' on all records?
Santosh,
Try below code :-
Trigger insertInvoice on Deliverable__c(before insert,before update){
List<Invoice__c> invoiceList = new List<Invoice__c>();
for(Deliverable__c dc:trigger.new){
if(dc.Implementation_Status__c=='Completed'){
Invoice__c in = new Invoice__c(Name='Test Invoice',Opportunity__c=dc.Opportunity__c,Invoice_Amount__c=dc.Estimate__c ); //Assuming Invoice Amount to be mapped with Estimate
invoiceList.add(in);
}
}
insert invoiceList;
}