You need to sign in to do that
Don't have an account?
Rahul
Hi Friends Can come one help me with this code.
I have picklist filed named boolean on contact object. which should be set to true if whe subject of the task is 'Mass Email'. There are 2000+ emails sent. for contacts and their subjct is mass Email which is created in the Activity history. Now i need to find them and update the boolean value to True where the subject is mass Email. I tried with the Following code but not working.
trigger toupdateboolean on task(before insert){
set<id> setid = new set<id>();
for(task tsk : trigger.new){
setid.add(tsk.whoid);
}
list<contact> lstcontact = new list<contact>();
for(Contact con :[select id,boolean__C,(select subject from tasks where subject='Mass Email') from contact where id=:setid]){
Contact cont = new contact();
cont.id=con.id;
cont.boolean__c='True';
lstcontact.add(cont);
}
update lstcontact;
}
but it Doesnot work. Can someone please help me?
trigger toupdateboolean on task(before insert){
set<id> setid = new set<id>();
for(task tsk : trigger.new){
setid.add(tsk.whoid);
}
list<contact> lstcontact = new list<contact>();
for(Contact con :[select id,boolean__C,(select subject from tasks where subject='Mass Email') from contact where id=:setid]){
Contact cont = new contact();
cont.id=con.id;
cont.boolean__c='True';
lstcontact.add(cont);
}
update lstcontact;
}
but it Doesnot work. Can someone please help me?
I would recommend having an After Trigger since the update is happening on another object. Hope you find below trigger helpful. It works on all different conditions such as insert, update, delete, undelete etc.. I have also tested it on my developer org.
Trigger Code:
Here is a visual representation of Trigger:
Once you create a task record with subject as Mass Email then it will populate TRUE on Boolean__c field.
If this question solves the query then please mark it as Best Answer!
There are two ways you can accomplish this update:
1) Via Data loader: (This is an EASY approach)
Export all existing tasks with ID only and them update them via data loader.
2) Via Anonymous Code Block in Developer Console :
- Create a field on Task object named Year_Created__c with formula as TEXT(YEAR( DATEVALUE(CreatedDate) ))
- Go to Developer Console - Debug - Open Execute Anonymous Window and the run the following code:
Keep changing the year to 2017, 2017, 2016... upto however many you have. Once the task is updated, the trigger will fire and do the magic.
Hope this helps!