You need to sign in to do that
Don't have an account?
Chad Moutes
Rollup Summary Trigger for a lookup relationship
I have a custom object called "Project" that looks up to the object "Account" and I would like to create a Trigger that simply tells me how many "Projects" are linked to that specific "Account". Im just looking for someone to point me in the right direction.
Any help would be greatly appreciated.
Any help would be greatly appreciated.
My apologies.
I'm going to assume you're familiar with the basics of trigger creation (where to go to create one, what the various contexts mean etc.)
Your trigger is going to fire whenever a record of a given type is updated/created/deleted/undeleted depending on how you setup the trigger. So, for the sake of explaination i'm going to assume you're writing this trigger on the project object.
Here's some highly annontated code to help get you started.
Ask questions!
All Answers
http://andyinthecloud.com/2013/07/07/new-tool-declarative-rollups-for-lookups/ (http://andyinthecloud.com/2013/07/07/new-tool-declarative-rollups-for-lookups/" target="_blank)
My apologies.
I'm going to assume you're familiar with the basics of trigger creation (where to go to create one, what the various contexts mean etc.)
Your trigger is going to fire whenever a record of a given type is updated/created/deleted/undeleted depending on how you setup the trigger. So, for the sake of explaination i'm going to assume you're writing this trigger on the project object.
Here's some highly annontated code to help get you started.
Ask questions!
I think we need to object typecast here, the line 27 would be
accountMap.put((Id)ar.get('account__c'),(Integer)ar.get('projectcount'));
You're right, type casting would be helpful here.
Yes, where you see me using "Account__c" thats the lookup *field*, which in your case would actually be "company_Name__c"
Yes. use the version bennie posted.
I appologize.
line 14 should read:
where your "project_count_field__c" is replaced by the fieldname you want to store your rollup count in on account.
Here is my line 14, im not getting an error saying : Illegal assignment from Object to Decimal at line 14 column 55
= (decimal) ar.get('projectcount');
I would like to add a after delete to this trigger, because i want the count to go down just incase someone for some reason would have to delete a project?