You need to sign in to do that
Don't have an account?
SFDCDevQA
Can a Task trigger update an object twice removed from it?
So I have a task trigger that triggers after Insert if the subject is a certain thing and attached to a quote. It then updates a quote field to show that the Quote was sent. I would also like to update the opportunity status when this happens and if possible I would like to do it without a second trigger. Can I do this? Here is my current trigger. I tried updating the list with opportunity.id and the updating part with the Opportunity.stage but just received errors.
Thanks,
Amanda
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | trigger QuoteAdoptionAgreementSent on Task (after insert) { // map tracks records on WhatID Map<String, Task> TaskMap = new Map<String, Task>(); for( Task record : Trigger.new ) { if( record.subject == 'Email: Sapling Learning Adoption Agreement') { TaskMap.put( record.WhatID, record ); } } if( TaskMap.keySet().size() > 0 ) // if there are no eligible Task records, end { // Pull all related Quotes out of the database in one set, finding them based on matching ID List<Quote> Quotes = [select id, name, Adoption_Agreement_Sent__c from Quote where ID in :TaskMap.keySet() ]; // update Quote Adoption Agreement Sent field from the matching record for( Quote Quote : Quotes) { Task record = TaskMap.get( Quote.id ); // grab the correct record from the map Quote.Adoption_Agreement_Sent__c =date.today(); } // Save Date value to the database Database.SaveResult[] results = Database.update( quotes ); for( Database.SaveResult result : results ) if( !result.isSuccess() ) System.debug( '<< ' + result.getErrors().size() + ' update error(s) on Quotes: ' + result.getErrors()[0].getMessage() ); } } |
Please share the Error !!!