You need to sign in to do that
Don't have an account?
Tillu
Unable to update opportunity record with trigger ?
From opportunity , while creating Task...if the Task is associated with opportunity via 'Related To' field Then Opportunity fields need to populate some values and update the Opportunity record. I have tried but the Opportunity record was not updated.
Please check where i have missed ?
trigger TaskonOpp on Task (before insert,before update) {
set<Id> Tid = new set<id>();
for(Task t:trigger.new){
Tid.add(t.whatid);
}
List<Opportunity> ollist = [select id,name from opportunity where id in:Tid];
for(Task T : Trigger.new){
for(Opportunity O:ollist){
if(T.whatId==O.id&&T.RecordType.name=='Annuity Log a Call'&&T.Activity_Type__c == 'Voicemail'){
O.StageName = '3-Rep follow up - VM';
O.CloseDate = System.ToDay()+30;
}
if(T.whatId==O.id&&T.RecordType.name=='Annuity Log a Call'&&T.Activity_Type__c == 'Client Meeting - IW'){
O.StageName = '4-Client Meetings';
O.CloseDate = System.ToDay()+7;
}
if(T.whatId==O.id&&T.RecordType.name=='Annuity Log a Call'&&T.Activity_Type__c == 'Business drop'){
O.StageName = '5-Paperwork/Ticketing incoming';
O.CloseDate = System.ToDay()+7;
}
update ollist;
}
}
Please check where i have missed ?
trigger TaskonOpp on Task (before insert,before update) {
set<Id> Tid = new set<id>();
for(Task t:trigger.new){
Tid.add(t.whatid);
}
List<Opportunity> ollist = [select id,name from opportunity where id in:Tid];
for(Task T : Trigger.new){
for(Opportunity O:ollist){
if(T.whatId==O.id&&T.RecordType.name=='Annuity Log a Call'&&T.Activity_Type__c == 'Voicemail'){
O.StageName = '3-Rep follow up - VM';
O.CloseDate = System.ToDay()+30;
}
if(T.whatId==O.id&&T.RecordType.name=='Annuity Log a Call'&&T.Activity_Type__c == 'Client Meeting - IW'){
O.StageName = '4-Client Meetings';
O.CloseDate = System.ToDay()+7;
}
if(T.whatId==O.id&&T.RecordType.name=='Annuity Log a Call'&&T.Activity_Type__c == 'Business drop'){
O.StageName = '5-Paperwork/Ticketing incoming';
O.CloseDate = System.ToDay()+7;
}
update ollist;
}
}
Have you checked whether the trigger was invoked successfully/whether it gave any error ?
If so, please provide that information.
It would be a good idea to put in System.debug() statements in the code and check the debug logs so that you can zero in on the problem.
Regards,
Lakshmi.
If the trigger is invoked successfully and still no value is updated, chances are it may not be entering any of the if loops which set the values to be assigned.
Furthermore, you could add a query to the beginning of your trigger to grab the Annuity Log a Call record type, and then filter out any irreleavant Tasks in your first for-loop. This should help improve performance by just a bit.