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
Samuel Gonsalves 8Samuel Gonsalves 8 

trigger to create and update a field in custom object based on standard object in salesforce

Hi All,

In opportunity i have created an INVOICING object. I want all the quote line items details to get UPDATE OR CREATE under invoicing object. When a new product is added under quote same should be created in invoicing object.

Product: Line Item Description-details copied from the quote

Quoted Sales Price - details copied from the quote
Invoice Sales Price(Invoicing Object)

Quoted Quantity-details copied from the quote
Invoice Quantity (Invoicing Object)

Quoted Total Price-details copied from the quote
Invoice Total Price (Invoicing Object)

Can anyone please help me out with this.

Thanks.

Regards,
Samuel

 
Himanshu ParasharHimanshu Parashar
HI Samuel,

below code should work for your.
Trigger InsertInvoice (after insert)
List<Invoice__c> lstInvoice = new List<Invoice__c();
for(Quote q : Trigger.new)
{
    Invoice__c invoice = new Invoice();
    invoice.total_price__c = q.TotalPrice;
    invoice.quantity__c= q.quantity;
    invoice.product__c=q.Product2Id;
    invoice.quote__c = q.id;
    lstInvoice.add(invoice);
}

if(lstInvoice.size()>0)
   insert lstInvoice;


Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant

P.S.  If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
 
Samuel Gonsalves 8Samuel Gonsalves 8
How i will be able to create invoice section under opportunity. If ill create lookup then i will need to create a lookup field. I want invoice as a section under opportunity which shows same as quote line item. Now quote line items are under quote and quote is under opportunity. Please help me with this pls.