+ Start a Discussion
balaji_SFDCbalaji_SFDC 

How to refresh the record page when the trigger is fired

Hi Experts,

When i change the status filed to 'closed-converted' in Lead.The related completed tasks(Activity History) of lead record gets deleted using trigger.

  Could anyone please help me how to achieve this.Thanks in advance

Thanks,
Venkat
ShashForceShashForce
Hi, Here is an example:

trigger deletecompletedtasks on lead(after insert, after update){
	set<Id> leadIds = new set<Id>();
	list<task> deletetasks = new list<task>();
	for(lead l:trigger.new){
		if(l.status=='closed-converted'){
			leadIdset.add(l.Id);
		}
	}
	for(task t:[select Id,status from task where status='completed' and whoId IN :leadIds]){
		task tk = new task();
		tk.Id = t.Id;
		deletetasks.add(tk);
	}
	delete deletetasks;
}

If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.

Thanks,
Shashank