You need to sign in to do that
Don't have an account?
Lisa Kattawar
Copy Activity records to Custom "Marketing Activity" Object
Can someone help me with a trigger that will do the following (hopefully this is just a matter of sharing code you've already written for a similar situation):
If Activity is created by "Marketing" (I know this based on created by user)
Copy Activity Record to Custom Marketing_Activity__c object
Delete Activity Record
Thanks in Advance!!
Lisa
If Activity is created by "Marketing" (I know this based on created by user)
Copy Activity Record to Custom Marketing_Activity__c object
Delete Activity Record
Thanks in Advance!!
Lisa
Try below code :-
If this helps,please mark it as best answer to help others :)
All Answers
While saving these two u can only store these ids in Marketing Activity object.
WhatId__c = t.Whatid
Whoid__c = t.WhoId
Here WhatId__c, Whoid__c are text fields.
I ended up with the following Trigger (after minor changes for exact field names, etc...). I'm getting a DML exception on line18 (which is delete lstTsk;). When I remove this line, it works great...BUT, I still have my Task (since I don't have the line to delete it).
Any ideas for me? I truly appreciate your help! I'm not a developer, but I'm trying :)
This is the error I get when I leave in line 18.
Trigger CreateMarketingActivity on Task(after insert){
List<Manticore_Marketing_Activity_History__c> lstMA = new List<Manticore_Marketing_Activity_History__c>();
List<Task> lstTsk = new List<Task>();
for(Task t :Trigger.new){
// Add all fields from task
Manticore_Marketing_Activity_History__c ma = new Manticore_Marketing_Activity_History__c
(Contact__c = t.WhoId,
EventDescription__c = t.Subject
);
lstMA.add(ma);
lstTsk.add(t);
}
If(!lstMA.isEmpty() && !lstTsk.isEmpty()){
try{
insert lstMA;
delete lstTsk;
}catch(DmlException e){
System.debug('DML failed due to '+e);
}
}
}
Source organization: 00DA0000000HFaB (null)
CreateMarketingActivity: execution of AfterInsert
caused by: System.SObjectException: DML statment cannot operate on trigger.new or trigger.old
Trigger.CreateMarketingActivity: line 18, column 1
Try belo code.
Try below code :-
If this helps,please mark it as best answer to help others :)
Thank you both!! I truly appreciate the help. I'm marking Vinit's answer as "best" because he also addressed my need to check the user profile. I have this working in our sandbox and I'm ready to move it to production (I only made one little change...I had to move the "delete" logic under the if statement above it because I only want to delete from Activity if I added it to Marketing Activity).
Again, thank you both for your help!