You need to sign in to do that
Don't have an account?
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';
}
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';
}
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
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