2

What I'm doing is retrieving a PDF and save that PDF into the notes & attachment of my current object. Everything works fine, I'm able to get the base 64 encoding of the PDF, convert it and save as the file.

Now from what I have understood, when uploading a PDF manually, Salesforce operates on it, being then able to preview it directly on the website. This does not happen with my programmatically created PDF.

Any idea on how to force Salesforce to load the preview by code? I have already found that the user can force reload the preview, but what I want is to create the preview with my files.

The code currently looks like this:

        String test = webserviceOut.SI_Quotation_Out('0020015480');

    //Blob txtBlob = Blob.valueOf(test); //Convert it to a blob
    Blob txtBlob = EncodingUtil.base64Decode(test);

    Attachment attach = new Attachment(); //Make an attachment
    attach.Name ='text.pdf';  
    attach.Body = txtBlob;
    attach.ContentType= 'application/pdf'; //Signal what the file's MIME type is
    attach.ParentID = id;
    insert attach;

Edit1: To show what the actual difference is, prova is a PDF loaded by the UI of salesforce, while text.pdf is one generated by my code.

enter image description here

Now when I click on prova I'm able to load the preview, while clicking of text I'm not.

  • '/servlet/servlet.FileDownload?file=' + AttachmentId works for me with PDF and I am abke to view. – Tushar Sharma Dec 17 '18 at 9:44
  • Meaning that by going to that link you are able to see the preview? My problem is that when I click on the PDF it just ask to download instead of showing that nice pop up with the PDF inside – Zeno Trevisan Dec 17 '18 at 10:36
  • Yes I am able to view. It may be your browser setting – Tushar Sharma Dec 17 '18 at 10:40
  • I have added a screenshot trying to explain myself in a better way – Zeno Trevisan Dec 17 '18 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.