You need to sign in to do that
Don't have an account?
NikiG22
Rollup summary on Contact
Hello -
I am having some issue with adding a value on a custom object then pushing that to a hidden field on a contact using APEX.
I am trying to count the number of active__c Resume_subscriptions__c on a contact. this is not a master relationship so im having issues counting the ones that are active__c only and populating the Active_Resumes__c field on the contact with the active__c count.
There are many code samples out there but i have no idea where to start. YOur help is Very Much Appriciated!!
Cheers,
Niki
For anyone still looking here.
The updated code is
All Answers
I have gotten this far: But it isnt updating my field Active_Resumes__c on my contact
Okay,
So a few things I want to point out..
The trigger will have to be on the child object Resume_Subscriptions__c as that is where insert and update will happen
The best way that I can think of is to use aggreate queries, as the trigger can be fired for multiple records with different contacts.
The trigger will also have to fire on delete of a child record.
Since it is a lookup field, you will also need to take care of situation where the contact alignment changes for a Resume_Subscriptions__c
Basically the idea is to
1. Iterate through trigger.new and collect all the Contact IDs in a set 'ContSet'
2. Issue an aggregate query to calculate the count of child records which are to the contact avaialble in ContSet.
3. Work with the query results to store the contents in a map of contact id, count..
4. Use this map to update the field value of contact.
Please use the below code. You might have to tweak it to work for you.
Thank you soooo much for your help!
I added the code tweeked it but i get the following error:
Error: Compile Error: Incorrect SObject type: Resume_Subscriptions__c should be Contact at line 1 column 1
here is the modified code:
I have a good chance of being wrong, but maybe you cant just edit the existing trigger for this.
As we are changing the object on which we are writing the trigger.
You will have to go to Setup->Create->Objects->Resume_Subscriptions__c->Triggers->New
and then try pasting this code.
Thanks,
Jerun Jose
Ya im special, that worked. But now im getting an error message
Thank you again for all your help
I took out:
----------------------------------------------------
After Update
---------------------------------------------------
Not its:
---------------------------
after update, before delete
---------------------------
That seemed to work, i will test is and mark it if it a resolution.
If you are still looking for this, then yeah using oldmap on an insert trigger will be a problem.
For anyone still looking here.
The updated code is