You need to sign in to do that
Don't have an account?
anil87
Hi Regarding Activity trigger
Hi Everyone,
I Have to add the owner change to the below Trigger that updated Last Call Result and Notes field.Now i want to change owner to user who created/modified the activity that Triggered?
this is my trigger
trigger StatusChangesAccount on Task (after insert,after update)
{
List<Contact> cons = new List<Contact>();
List<Opportunity> opps = new List<Opportunity>();
List<Account> accs = new List<Account>();
List<Creditor__c> creds = new List<Creditor__c>();
for(Task t : trigger.new )
{
String wtid = t.whatid;
system.debug('*** What ID : ' + wtid);
String whid = t.whoid;
system.debug('*** Who ID : ' + whid);
if(whid != null)
{
try
{
cons.add( new Contact( id = whid, Last_Call_Result__c = t.CallDisposition) );
system.debug('*** Contact Inserted in first IF ');
}
catch(Exception e){}
}
if(wtid != null)
{
try
{
creds.add(new Creditor__c(id = wtid, Last_Call_Result__c = t.CallDisposition ));
system.debug('*** Creditor__c Inserted in first IF ');
}
catch(Exception e){}
try
{
accs.add(new Account(id = wtid, Last_Call_Result__c = t.CallDisposition ));
system.debug('*** Account Inserted in first IF ');
}
catch(Exception e){}
try
{
opps.add(new Opportunity(id = wtid, Last_Call_Result__c = t.CallDisposition ));
system.debug('*** Oppurtunity Inserted in first IF ');
}
catch(Exception e){}
}
}
try{update accs;system.debug('Account Update');}catch(Exception e){}
try{update opps;system.debug('Oppurtunity Update');}catch(Exception e){}
try{update cons;system.debug('Contact Update');}catch(Exception e){}
try{update creds;system.debug('Creditor Update');}catch(Exception e){}
}
{
List<Contact> cons = new List<Contact>();
List<Opportunity> opps = new List<Opportunity>();
List<Account> accs = new List<Account>();
List<Creditor__c> creds = new List<Creditor__c>();
for(Task t : trigger.new )
{
String wtid = t.whatid;
system.debug('*** What ID : ' + wtid);
String whid = t.whoid;
system.debug('*** Who ID : ' + whid);
if(whid != null)
{
try
{
cons.add( new Contact( id = whid, Last_Call_Result__c = t.CallDisposition) );
system.debug('*** Contact Inserted in first IF ');
}
catch(Exception e){}
}
if(wtid != null)
{
try
{
creds.add(new Creditor__c(id = wtid, Last_Call_Result__c = t.CallDisposition ));
system.debug('*** Creditor__c Inserted in first IF ');
}
catch(Exception e){}
try
{
accs.add(new Account(id = wtid, Last_Call_Result__c = t.CallDisposition ));
system.debug('*** Account Inserted in first IF ');
}
catch(Exception e){}
try
{
opps.add(new Opportunity(id = wtid, Last_Call_Result__c = t.CallDisposition ));
system.debug('*** Oppurtunity Inserted in first IF ');
}
catch(Exception e){}
}
}
try{update accs;system.debug('Account Update');}catch(Exception e){}
try{update opps;system.debug('Oppurtunity Update');}catch(Exception e){}
try{update cons;system.debug('Contact Update');}catch(Exception e){}
try{update creds;system.debug('Creditor Update');}catch(Exception e){}
}
You want to update the owner for whom(Account,contact,opportunity,etc.).Which one you want to update?
if i'm working an a account it should update the account owner to task creating user ans similarly to contact and opportunity