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
Raphael BendenounRaphael Bendenoun 

Formating HTML through the Salesforce API

We are using the Salesforce Api to order to create new contacts on Salesforce and one of the field is a rich-text and is able to receive HTML We are trying to format this field as a list as in the following example:
{
"country": "Algeria",
"description": "<<ul><li>Description: Broker</li><li>Additional Notes: Hi how are you</li><li>Property Name: none</li><li>Property Address: none</li><li>City: None</li><li>Current Use: Land</li><li>Interested In: Renting the property</li><li>Asking Price: 500</li><li>Currency: AWG</li></ul>",
"email": "jojojo@gmail.com",
"firstName": "Johnnny",
"lastName": "Doee",
"web_to_lead": true
}
The contact is well sent to salesforce but the description instead of being displayed that way:
  • Description: Broker
  • Additional Notes: Hi how are you
  • Property Name: none
  • Property Address: none
  • City: None
  • Current Use: Land
  • Interested In: Renting the property
  • Asking Price: 500
  • Currency: AWG
it is display as a string in the following way: Descrption: Broker - Additional Notes: hi how are you - Property Name: none - .........

Any idea how could I keep the desired HTML format? 
SubratSubrat (Salesforce Developers) 
Hello Raphael ,

To display the rich-text field in the desired format with HTML list tags, you need to use the Salesforce field's "rendered" attribute. This attribute allows you to specify whether to display the field's value with the rendered HTML tags or as plain text.

Here's an example of how to use the "rendered" attribute in SOQL to retrieve the contact record with the desired HTML format:
 
SELECT Id, Country, Description_c, Email, FirstName, LastName, Web_to_Leadc, Description_c.rendered
FROM Contact
WHERE Id = 'your_contact_id'

Note that we added ".rendered" to the Description__c field to indicate that we want to retrieve the field's rendered value with HTML tags. This will give you the desired output with the HTML list tags.

If you're creating a new contact record, you can include the ".rendered" attribute in the rich-text field value as well. Here's an example of how to do that in Apex:
 
Contact newContact = new Contact();
newContact.Country = 'Algeria';
newContact.Description__c = '<<ul><li>Description: Broker</li><li>Additional Notes: Hi how are you</li><li>Property Name: none</li><li>Property Address: none</li><li>City: None</li><li>Current Use: Land</li><li>Interested In: Renting the property</li><li>Asking Price: 500</li><li>Currency: AWG</li></ul>';
newContact.Email = 'jojojo@gmail.com';
newContact.FirstName = 'Johnny';
newContact.LastName = 'Doe';
newContact.Web_to_Lead__c = true;
newContact.Description_c = newContact.Description_c + '.rendered';
insert newContact;

Hope it helps !
Thank you.