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
inanskarinanskar 

Triiger for updating or deleting for a field

Gud afternoon guys

I'm uday new to salesforce.. i just got wondering for a query  that

i Created a Custom Object Called Invoice with the following fields
Invoice NUmber: Auto Number
Invoice Date: Date
Opportunity: Lookup(Opportunity)
Invoice Status: Picklist (Open, Partially Paid, Fully Paid)

 

But i'm wondering how to create this fields can u jst please guide how to create this fields
Invoice Total: Roll Up Inv Line Item ( Total Field)
Invoice Quantity: Roll up Summary (Qty Invoice)

and i also Created another custom object called Invoice Line Item with following fields
Inv LI ID: Auto Number
Invoice: master Detail (Invoice)
Product: Lookup(Product)
Price: Currency
Qty: Number
Total: Formula (Price*Qty)

but i'm looking how to write these following triggers for:

Each Opportunity can have multiple Invoices.

  • Create a Field on Opportunity called Total Invoiced Amount (Sum of Invoice total on Invoice). If we make any changes on Invoice or delete it then Total Invoiced Amount should also change.
  • Create a field called Total Invoiced Quantity(Type = Number) on Opportunity Object. The field should calculate and display the total Qty of Invoice Line items and populate in opportunity Total Invoiced Quantity field.
  • Create three fields Open Invoices Total, Partially Paid Invoices Total and Fully Paid Invoices total with type = number on opportunity object. The field should show the sum of all open invoices in Open Invoices Total Field, Sum of Partially Paid Invoices in Partiall Paid Invoices Total Field and Sum of Fully Paid Invoices in Fully Paid Invoices Total Field. If a status of an Invoice changes from Open to Partially paid then the field total fields should automatically adjust.

 

Can u please guide me for this.....................

                                                                                    Thanks in advance......

 

MikeGillMikeGill

You may not want to do this if you want to create invoices stand-alone

 

But if you change the relationship from lookup to master-detail, then you will be able to roll-up your values from the invoice lines all the way to the opportunity.