Question or Problem Statement:
One of our customers gets the quote template pdf file from Zuora by REST API and then inserts the pdf file to quote attachment object, but when he click the file link to view the pdf file, the error "Failed to load PDF document" occurred and this error only encountered in Chrome, Firefox worked well.
We checked the customer's code:
http = new Http();
req = new HttpRequest();
//same authorization we set up earlier, we can reuse it
req.setEndpoint(previewAttachmentURL); //the URL Zuora responds with upon success
req.setCompressed(true); //I've tried both true and false here.
res = http.send(req);
Blob zuorasPDF = res.getBodyAsBlob();
Attachment zPDF = new Attachment();
zPDF.Name = Quote.Name + '.pdf';
zPDF.ContentType = 'pdf';
zPDF.IsPrivate = false;
zPDF.ParentId = Quote.zqu__Opportunity__c;
zPDF.Body = zuorasPDF;
The contentType value "pdf" is not correct, there is one limitation for chrome pdf review, but Firefox was more flexible in handling. So the error only occurred in Chrome.
To fix this issue, change the contentType value to 'application/pdf' or just do not set the contentType value for the attachment record.