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
SFDC_EvolveSFDC_Evolve 

Read Word Document in the APEX

Hi

 

Actually .. I have upload the word document in the Salesforce .. . And read the Content and then convert it into the PDF.

 

 

Thanks 

SFDC_Evolve

 

Navatar_DbSupNavatar_DbSup

Hi,

Try the below code snippet as reference:

 

Account acc = [select Name from Account LIMIT 1];

Attachment att = [Select name,ContentType,body,ParentId,Description from Attachment where ParentId =: acc.Id];

// Get body of the attachment in Blob variable and converting it to string

Blob bodyBlob = att.body;

String bodyStr = bodyBlob.toString();

But this code works fine for attachments which have .rtf extension. When loading a String variable, it must be in UTF-8 format. This is a character-based format, not a byte-based format.

You can freely load valid HTML, XML, RTF, TXT, ASM, CPP, C, JAVA, PHP, PL, CSV, TSV, and ASP files (as examples). These are all character-based formats. They encode their data in a human-readable format. You need only a program such as Notepad to properly read and write these files. Because of UTF-8 restrictions on legal strings, you cannot load any type of file that may violate the rules for UTF-8.

So, you’ll probably need ActiveX, Silverlight, Java, or a remote server to process the file.

 

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.