You need to sign in to do that
Don't have an account?
Sandra O
Combine 2 Opportunity Triggers
Hello,
I'd appreciate help in combining these 2 triggers - I need to keep the functionality of both intact. Thank you in advance!!
1st one:
2nd one:
I'd appreciate help in combining these 2 triggers - I need to keep the functionality of both intact. Thank you in advance!!
1st one:
trigger linkGoLiveDate on Opportunity (after insert, after update) { Set<ID> myAccountIds = new Set<ID>(); Map<ID, Date> myMap = new Map<ID, Date>(); for (Opportunity o : Trigger.new) { if (o.go_live_date__c != null && o.accountid != null) { myAccountIds.add(o.accountid); myMap.put(o.accountid, o.go_live_date__c); } } if (myAccountIds.size() > 0) { List<Account> myAccounts = new List<Account>(); for (Account a : [select id from account where Service_Start_Date__c = NULL AND id in :myAccountIds]) { a.service_start_date__c = myMap.get(a.id); myAccounts.add(a); } update myAccounts; } }
2nd one:
trigger updateAccountOwner on opportunity (after insert, after update){ list<Id> accIds = new list<Id>(); list<Account> accounts = new list<account>(); for(opportunity o:trigger.new){ accIds.add(o.accountId); } for(account a:[select Id, ownerid from account where Id IN :accIds]){ for(opportunity opp:trigger.new){ if(opp.StageName == 'Live'){ a.ownerid=opp.client_service_rep__c; accounts.add(a); } } } update accounts; }
You can give this a try:
I think this is right, but I didn't compile it. Let me know how it goes. Good luck!
Rob Kemper - OpFocus
All Answers
You can give this a try:
I think this is right, but I didn't compile it. Let me know how it goes. Good luck!
Rob Kemper - OpFocus
can you tell me what you mean by compile?
When you save Apex code using the developer console or an IDE, Salesforce will do a syntax check to make sure that the grammer is correct.
Even if the syntax is correct the logic may be incorrect. The logic still needs to be validated either with a unit test, by manually testing in the Saleforce org and validating the results, or ideally both.
I did have to fix a few things, but not bad. I did test it out and functionality is good. Also ran all tests and it did not create any issues.
Again, thank you!