1

I am using JSForce for make api calls on salesforce. I am trying to add task using this api

const body = `<a href=${process.env.CONSOLE_URL}/myUrl/${id}>Click Here</>`
 const createObj = {
      WhoId: contact.Id,
      Subject: 'Call',
      CallDisposition : 'Call',
      Description : body
    };
 this.conn.sobject("Task").create(createObj, function(err, result) {
    if (err) return reject(err);
    return resolve(result);
  })

It is working as expected except the body(Description) part contains some html tags so it does not parse it instead paste as it is in the comment section. Kindly help.

Profer
  • 553
  • 8
  • 40
  • 81

2 Answers2

1

The backend probably escapes the html characters when the comment gets uploaded as a security measure; either before it gets stored in the database or before it gets returned to the client.
This should logically be done to disallow users to upload malicious tags and is standard.

Instead of uploading html tags, I would suggest uploading markdown tags in the body(description) instead on which you can find info here.

Then you need a script to convert the markdown back to html before rendering it.

html_programmer
  • 18,126
  • 18
  • 85
  • 158
1

Description is a plain-text field and as such it won't parse HTML. Generally speaking, the solution is to add a custom field of correct type to your object and populate this field. A field type that allows HTML and/or other markup is Text Area (Rich):

Text Area (Rich)

[...] users can format the field content and add images and hyperlinks. [...] The maximum field size is 131,072 characters, inclusive of all the formatting and HTML tags.

Unfortunately Activities (Task is a type of Activity) do not allow custom fields of Text Area (Rich) type. Another field type that is available for custom fields on Activities is URL:

Allows users to enter up to 255 characters of any valid website address. Only the first 50 characters are displayed on the record detail pages. When a user clicks the field in Salesforce Classic, the URL opens in a separate browser window. In Lightning Experience, internal URLs open in the same window and external URLs open in a separate browser window. In Salesforce console apps, the URL opens in a new workspace tab. In Lightning console apps, internal URLs open in a new workspace tab and external URLs open in a separate browser window.

Instead of HTML markup in one field, you could have plain text in the Description field with the instruction to click the link contained in your custom URL-typed field.

identigral
  • 3,920
  • 16
  • 31