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
cruttleycruttley 

How to assign the subject of a task to the email subject line

We have a trigger that creates a task for inbound email replies to existing cases. Currently, the task that is created has a subject line something like "An email reply has been received". This is stored as a system label.

Instead, I want the code to assign the subject line of the email to the task subject.

Any idea how I get the emails subject line, to replace the code seen below?

All help greatly appreciated.

 

 

 for (Integer i : emailIds) {
    if(((String)cases.get(trigger.new[i].ParentId).ownerid).startsWith('005')) { // no tasks for cases that are still assigned to a queue, only users
      Task t = new Task(Subject = System.label.Custom_Case_Email_Task_Subject,
                whatid = trigger.new[i].parentId,
                activitydate = Date.today()
                );
      
      // Assign task to the Level 1 Case Owner Id if it exists          
      if(cases.get(trigger.new[i].parentid).Level1_Case_Owner_Id__c == null) {
        t.ownerid = cases.get(trigger.new[i].parentid).ownerid;
      } else {
        t.ownerid = cases.get(trigger.new[i].parentid).Level1_Case_Owner_Id__c;
      }
      emailMsgsWithTasks.add(i); // note that this email has associated task, to update below.
      tasks.add(t);
    }
  }

Best Answer chosen by Admin (Salesforce Developers) 
kiranmutturukiranmutturu

as you said you are using inbound email services concept there you have a property to get the subject like  email.subject.  where email is the object for the Messaging.inboundEmail..

 

example code:

 

newTask.add(new Task(Description =  myPlainText,
           Priority = 'Normal',
           Status = 'Inbound Email',
           Subject = email.subject,
           IsReminderSet = true,
           ReminderDateTime = System.now()+1, 

All Answers

kiranmutturukiranmutturu

as you said you are using inbound email services concept there you have a property to get the subject like  email.subject.  where email is the object for the Messaging.inboundEmail..

 

example code:

 

newTask.add(new Task(Description =  myPlainText,
           Priority = 'Normal',
           Status = 'Inbound Email',
           Subject = email.subject,
           IsReminderSet = true,
           ReminderDateTime = System.now()+1, 
This was selected as the best answer
cruttleycruttley

Thanks Kiran. That helps.

I'm new to Apex and triggers....do you know what is the link to find a list of all objects and their properties/methods?

Chris