function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
rishi jaykar 1rishi jaykar 1 

Write a trigger :

1) Make two DateTime fields on contact object.

LastTaskCreatedTime

LastEmailSentTime


2) Whenever a task is created on Contact LastTaskCreatedTime field should be updated.


3) Whenever you send an email LastEmailSentTime field should be updated.

4) Make trigger as bulk
Ruwantha  LankathilakaRuwantha Lankathilaka
This is not a place to get your work done. This is a place to get help for the thnings that you need. To give a help you should post the material/code you tried.
Aman MalikAman Malik
++Ruwantha
Amit Chaudhary 8Amit Chaudhary 8
Please try below code
trigger TaskTrigger on Task( after insert, after update)
{

	Set<Id> setContId = new Set<ID>();
	for(Task tsk: Trigger.New){
		String strWhoId = tsk.whoid;
		if( strWhoId.startsWith('003') ){
			setContId.add(tsk.whoid);
		}
	
	}
	if(setContId.size() > 0 ){
		Map<Id,Contact> mapCont = new Map<Id,Contact>( [SELECT LastTaskCreatedTime ,LastEmailSentTime ,id from contact where id in :setContId]);

		List<Contact> lstContToUpdate = new List<Contact>();
		
		for(Task tsk: Trigger.New){
			String strWhoId = tsk.whoid;
			if( strWhoId.startsWith('003') && mapCont.containsKey(tsk.whoid) ){
				Contact cont = mapCont.get(tsk.whoid);
				cont.LastTaskCreatedTime = System.now();
				cont.LastEmailSentTime = System.now();
				
				lstContToUpdate.add(cont);
			}
		}

		if(lstContToUpdate.size() > 0 ){
			update lstContToUpdate;
		}	
	
	}
	
	

}
Let me know if this will help you