You need to sign in to do that
Don't have an account?
Gabe Rothman
Service class for trigger to update Oppty from related custom object
Can anyone give me some direction on a service class I'm trying to write? Essentially, I have a custom object called Transactions__c, which looks up to another custom object called PD_Data__c, which in turn looks up to the Account. When a field called Amount_Due__c on a Transaction record is updated to a value greater than 0, I want to set the stage on any open oppty on the same Account to closed won. See illustration below:
I've written some of the code, but I'm kinda stuck and I'm not sure if I'm even on the right track.
Any help would be greatly appreciated. Thanks!
I've written some of the code, but I'm kinda stuck and I'm not sure if I'm even on the right track.
public with sharing class CloseOutOpptyService { public static list<Transactions__c> filterAmountDueChange(map<id, Transactions__c> oldMap, list<Transactions__c> newList) { list<Transactions__c> temp=new list<Transactions__c>(); for (Transactions__c trxs : newList){ if ( (oldMap.get(trxs.id).pd_amount_due__c == null || oldMap.get(trxs.id).pd_amount_due__c == 0) && (trxs.pd_amount_due__c > 0) ){ temp.add(trxs); } } return temp; } public static Set<Id> closeOpptys (list<Transactions__c> trxAccount) { list<Transactions__c> trxAccountIds = [SELECT Id, Parent_PD_Data__r.SFDC_Account__r.Id FROM Transactions__c Where Id in: trxAccount]; Set<Id> accountIds = new Set<Id>(); for(Transactions__c trxAccountId : trxAccountIds) { accountIds.add(trxAccountId.Parent_PD_Data__r.SFDC_Account__c); } return accountIds;
Any help would be greatly appreciated. Thanks!
I did not write a test class to go with it and you will need one to deploy the trigger into production.
All Answers
I did not write a test class to go with it and you will need one to deploy the trigger into production.
I'm assuming that the one trigger you have firing for each object is making calls to public classes for methods to execute upon particular events ( insert, update, before/after, etc). If that's the case you can just strip out line 1 and 30 from above and build a method around it instead then insert it into an existing class. The add a line to your trigger for that SObject and call our the method to fire after update.
You will need to update anything that specifies trigger.new[0] in the above to a variable you map to the record for Transaction__c.
Clay