• Rajendiran Karuppaiah 1
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
I am trying to fetch few pdf and xls files from SFDC org1 and store it in SFDC org2. I could get the contentversion versondata body using the service '/services/data/v42.0/sobjects/ContentVersion/06890000003oTkqAAE/VersionData'. But I am not sure what is the format of the response and how to store it in SFDC org2. I tried the below code, it creates pdf and xls files but the files are corrupted.
Http h = new Http();
	HttpRequest req = new HttpRequest();
	req.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm() + '/services/data/v42.0/sobjects/ContentVersion/06890000003oTkqAAE/VersionData');
	req.setMethod('GET');
	req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());
	req.setHeader('Content-Type', 'application/json');
	HttpResponse res = h.send(req);
	
	contentVersion cv = new contentVersion();
	cv.FirstPublishLocationId = '5002aikl0000aes';
	cv.Title = 'Solution pdf';
	cv.PathOnClient = 'Solution.pdf';
	cv.VersionData = Blob.valueof( res.getbody() );
	
	insert cv;

 
I am trying to fetch few pdf and xls files from SFDC org1 and store it in SFDC org2. I could get the contentversion versondata body using the service '/services/data/v42.0/sobjects/ContentVersion/06890000003oTkqAAE/VersionData'. But I am not sure what is the format of the response and how to store it in SFDC org2. I tried the below code, it creates pdf and xls files but the files are corrupted.
Http h = new Http();
	HttpRequest req = new HttpRequest();
	req.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm() + '/services/data/v42.0/sobjects/ContentVersion/06890000003oTkqAAE/VersionData');
	req.setMethod('GET');
	req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());
	req.setHeader('Content-Type', 'application/json');
	HttpResponse res = h.send(req);
	
	contentVersion cv = new contentVersion();
	cv.FirstPublishLocationId = '5002aikl0000aes';
	cv.Title = 'Solution pdf';
	cv.PathOnClient = 'Solution.pdf';
	cv.VersionData = Blob.valueof( res.getbody() );
	
	insert cv;

 
Hi,
I need to fetch my content of my document which is uplaoded to the attachment.
I need to pass the query in REST API through workbench
So far I tried , Select id,ContentDocumentId,ContentDocument.LatestPublishedVersionId from ContentDocumentLink where LinkedEntityId IN ('a011I00000D55nx') , This gives the result as url,
Anyone of them pleae let me know how to get the body of the file?