You need to sign in to do that
Don't have an account?
suresh143
Trigger: update child object field with parent's value (it updates via formula)
Hi swetha so you great i think so and one more is there
write trigger account and opp then once created opp how many number of opp is displyed in account object in number of opps field in acc object
@suresh143,
The trigger below will run whenever an Opportunity (or Opportunities) is inserted, updated, deleted or undeleted. It finds all the related Account records, and then counts how many Opportunities are on each of those Accounts. It modifies a custom field on Account, called "Num_Opportunities__c", and updates the Account records.
If this helps, please mark it as a solution, and give kudos (click on the star) if you think I deserve them. Thanks!
-Glyn Anderson
Certified Salesforce Developer | Certified Salesforce Administrator
I had an error in the code I provided. I have edited my previous post to fix the problem. I have compiled and tested this trigger in my DE org and it does exactly what I described: Whenever an Opportunity is created, modified, deleted or undeleted, it will update the Account with the correct number of related Opportunities. The field will not be initialized, however, until a related Opportunity is triggered.
To load all of the Account records with the correct counts, you could run the following in the Execute Anonymous window:
This should work, unless your org has more than 50,000 Opportunity records.
If this is not your requirement, my apologies. I am having difficulty understanding.
-Glyn
You will have to replace "Num_Opportunities__c" in my code with the developer name of your custom field - "No_of_Opportunitys__c", or whatever it is...
-Glyn