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
Prathap I am :)Prathap I am :) 

can we get PDF files in documents object using REST API

Hi 

can we get PDF files in documents object using REST API ??

Plese see following snippet . it is retriving the blank pdf template . pls help me in this 

public void Attachementinfo(){
       
        //Set the Rest Class End Point URL
        String url = 'https://ap1.salesforce.com/services/data/v29.0/sobjects/Document/01590000002nNOL/body';
       
        Http h = new Http();
        HttpRequest req = new HttpRequest();
        req.setEndpoint(url);
        req.setMethod('GET');
        String authorizationHeader = 'OAuth ' +SessionId;
        req.setHeader('Authorization',authorizationHeader);
        HttpResponse res = h.send(req);
        if(res.getStatusCode()==200){
       
       
        Document d=new Document();
        d.body=blob.valueOf(res.getBody());
        d.description='Hello Welcome to Documents';
        d.Keywords='marketing,sales,update';
        d.FolderId='00li0000001jDVB';
        d.Name='Marketing Brochure Q1';
        d.Type='pdf';
        insert d;
        Attachmentbody='Document has been created with id : '+d.id;
        }
        else
        Attachmentbody='Attachment is Failed';
    }
Ashish_SFDCAshish_SFDC
Hi Prathap, 


See the file feed resource section on pg# 106 in the doc below, 

http://www.salesforce.com/us/developer/docs/chatterapi/salesforce_chatter_rest_api.pdf


Regards,
Ashish
Ajay_SFDCAjay_SFDC
Hi Prathap ,

Try the following way :
1. 
HttpResponse res = new HttpResponse();
Blob beforeBlob = res.getBodyAsBlob();

// Insert it in Attachment or in Document
Attachment objAttachmnt = new Attachment(parentId ='Parent ID', name= 'Shipment.pdf', body = beforeBlob);
  insert objAttachmnt;

or 
2. 
Attachment objAttachmnt = new Attachment(parentId = sObjectToBind.Id, name= 'Contract.pdf', body = EncodingUtil.base64Decode(strContractBodyStream));
             insert objAttachmnt;

Regards ,

Ajay