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
Preeti Khanna 10Preeti Khanna 10 

Count records on child objects

I am new to salesforce and need your help urgently.
 I have an object A having field say Opportunity.
 In object B,I have an field of lookupfield of opportunity field from object A and one qty field in object B
 I can have multiple records in object B for one opportunity.
like in record 1  - Opp1   qty 2
in record 2 -        Opp1   qty 3
in record 3 -        Opp1   qty 4
in record 4 -         Opp2 qty 5 then in total field of object B for opp2 total to be displayed as 5.
In object B in total field i want to display total count as (2+3+4)  whenever field is updated for Opp1 .
Count should be updated whenever qty is inserted/updated/deleted in object B
 
Kapil KaushikKapil Kaushik
Hi Preeti,

Please clear your question. Can you please mention your object structure clearly ? 
You should write it in this way like,

Object Name
     - Field1
     - Field2

Then we can help you easily.

Thanks,
Kapil Kaushik
Preeti Khanna 10Preeti Khanna 10
Hi Kapil,


Custom Object 1 - SubOrder
Field 1 in SubOrder - Opportunity(Lookup field)
Field 2 in SubOrder - Qty 
Field 2 in SubOrder - Total qty

For one opportunity we can have multiple suborders.
Like Opp1 - suborder 1  - qty2
      Opp1   - suborder2 - qty3
opp1 - suborder - qty 4

Same way it will work for other opportunities.

For all suborders total qty should be upated as (1+2+4 = 7)
It should keep on updating.

Regards,
Parry