+ Start a Discussion
anvesh@force.comanvesh@force.com 

Please give some solution?

Hii evryone i already asked this  question but i didnt got any answer from anybody...again i have serious issue with this topic.....if anyone understands please  tell me your solution.....i will  breifly  clearly explain my task understand step by step...

 

 

 

1)When we click Home  and scroll down we  have  "My Task" when we click new and we create  Task.  when we click new we ll see  fields , in that we   have   'Subject' , and  'Comments'  fields also. let it put aside.

 

2) click contacts , when we open any  existed contact  record  in below we will found  "Activity History"block in that we have  "send an email button"...

 

so  now  when i  click "send an email" button  the email page will opened with appropriate contact....and  we will fill details like  cc,BCC, Subject,Body  in the  email page. and we click  'send'  button to send email.

 

Now  the Requirement  is  when i click the  send button , a  new Task should need to create automatically (In first step it is manually)  and  Task  subject  is  populated by  email subject and  Task  comments  is  populated by  email Body.

 

How  should write  trigger for this...

 

i  found that  there are  no  email  fields are existed like  emails (subject , body ,cc , BCC  because it is standard and designed by salesforce.) so how should i know the fields apis name. but we have Task fields  like  subject,comments in Customize ---> Activities--> Task feilds.

 

can we  write trigger  between 2  objects. (because contacts email data need to save on Task.they are two diff objs)...

Best Answer chosen by Admin (Salesforce Developers) 
Sonali BhardwajSonali Bhardwaj

You can write trigger on task. Below might be one solution.

 

trigger createTaskForEmail on Task (after insert) {
    list<Task> tasks = new list<task>();
    for (Task t : trigger.new) {
        if (t.status == 'Completed' && t.subject.startswith('Email:')) {
            task t1 = t.clone();
            t1.status = 'Not Started';
            tasks.add(t1);
        }
    }
    if (tasks.size() > 0)
        insert tasks;
}

 

All Answers

Sonali BhardwajSonali Bhardwaj

You can write trigger on task. Below might be one solution.

 

trigger createTaskForEmail on Task (after insert) {
    list<Task> tasks = new list<task>();
    for (Task t : trigger.new) {
        if (t.status == 'Completed' && t.subject.startswith('Email:')) {
            task t1 = t.clone();
            t1.status = 'Not Started';
            tasks.add(t1);
        }
    }
    if (tasks.size() > 0)
        insert tasks;
}

 

This was selected as the best answer
anvesh@force.comanvesh@force.com

Thank you  very  much....but  small  problem, it  displays  email  subject  in  task  subject  correctly....but  it   displays  all  Cc , Bcc , Addition to , Body  messages  in  Task  Comments.....it  needs to  displays  only  Body  message  in  comments......

Sonali BhardwajSonali Bhardwaj
trigger createTaskForEmail on Task (after insert) {
    list<Task> tasks = new list<task>();
    for (Task t : trigger.new) {
        if (t.status == 'Completed' && t.subject.startswith('Email:')) {
            task t1 = t.clone();
            t1.status = 'Not Started';
            t1.description = t.description.substringAfter('Body:');
            tasks.add(t1);
        }
    }
    if (tasks.size() > 0)
        insert tasks;
}

 

anvesh@force.comanvesh@force.com

We  Have a  problem  with this trigger.....two  same tasks are  created  when we send an email....one is  subject and body  populated correctly in  tasks subject and comments...and  another  task also created  and in that  comments  populated from   emails  CC,BCC,Additional to,Body...........

 

i need only  subject and body   should maps  correctly in  tasks subject and tasks comments.  please  Correct this. Thanks  in Advance