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
Salesforce BeginnerSalesforce Beginner 

how to read description field of the task in Salesforce

Hello All,

I am writing a trigger on Task. When a new task is created, I am using the who.id (in my case mostly lead) and converting lead in to Account, contact and opp. Duing this process I am reading subject line (standard subject pattern) of the task to use the fields in the contact creation. example subject line: NewTask-email@email.com-field3-field4.

Note : ' - ' is the delimiter.

I am using as below:
if(task.Subject.indexOf('NewTask-') > -1) 

Now, I have a similar requirement to read the standard pattern (company-firstname-lastname-phoneno) etc from the decription(body/comments) field of the task. 

If anybody has any thoughts please share.
Best Answer chosen by Salesforce Beginner
Salesforce BeginnerSalesforce Beginner
Hello All,

I tried below and I got what I was looking for. Posting it here in case if anybody in future comes across this.

Statements:

string test = tk.Description;
 system.debug('The description of the task is'+test);
 List descFields = test.split('-', 4); // This statement does the trick
 system.debug('The new body fields are: '+descFields[0]);
system.debug('The new body fields are: '+descFields[1]);
system.debug('The new body fields are: '+descFields[2]);
system.debug('The new body fields are: '+descFields[3]);