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
Nagarjuna Reddy NandireddyNagarjuna Reddy Nandireddy 

HOW TO WRITE A FOR CONTACT AND TASK

Hi,
How to write triggger for
when i am creating contact like below picture.....
User-added image

after creation of contact than automatically creates task...like below picture 
in contact record    
if i give phone automatically creates call task or if i give email automatically crates email or both.....like below

User-added image

please help gor this.........

Thanks&regards
Nagarjuna Reddy Nandireddy



 
BALAJI CHBALAJI CH
Hi Nagarjuna,

Please find below trigger as per your requirement.
 
trigger ContactTask on Contact (after insert) {
    
    List<task> TaskList = new List<task>();
    for(Contact c: Trigger.New)
    {
        if(c.Phone != null && c.Email != null)
        {
            task t = new task(WhoId = c.Id, Subject = 'Call');
            TaskList.add(t);
            
            task t1 = new task(WhoId = c.Id, Subject = 'Email');
            TaskList.add(t1);
        }
        
        else if(c.Phone == null && c.Email != null)
        {
            task t1 = new task(WhoId = c.Id, Subject = 'Email');
            TaskList.add(t1);
        }
        
        else if(c.Phone == null && c.Email != null)
        {
            task t = new task(WhoId = c.Id, Subject = 'Call');
            TaskList.add(t);
        }
    }
    Insert TaskList;
}

Let me know if that helps you.

Best Regards,
BALAJI