4

i am new to salesforce programming , and i am trying to send a file through HttpRequest to a 3rd party . the file i am trying to send is a report converted to csv format or text !! is there a way to do that ? and if there is at least tell me the functions or the classes that i need to use, or how to do it ?!

many thanks

8

You can get the contents of the report by using a PageReference:

String reportText = new PageReference('/'+reportId+'?csv=1').getContent().toString();

From there, you can send the data to your third-party server:

HttpRequest req = new HttpRequest();
req.setEndpoint(endpoint);
req.setBody(reportText);
req.setHeader('Content-Type','text/csv');
req.setHeader('Content-Length',String.valueOf(reportText.length()));
req.setMethod('POST');

HttpResponse response = new Http().send(req);
// Check for 200 status here

Note: You can only use this technique in synchronous, non-trigger context (so, a Visualforce page or RemoteAction/webservice/etc call). Batches, triggers, test methods, apex email services, and scheduled jobs aren't allowed to use getContent.

2
  • thank you my friend , you are awesome :) you are my savior :) , maybe you can help me with this too though , how do i overcome the 3MB limit when sending a post ? is there some indirect way ? – eassa May 18 '15 at 6:25
  • @eassa The 3MB limit is a hard limit. You can't break it. If you had control of the receiving application, you could write a method that allows partial file transfers, and some systems might have a method of uploading parts of a file (like a sort of "resume" method), but that's typically pretty rare. – sfdcfox May 18 '15 at 6:42
1

You should be able to retrieve report data using the Analytics API. I'm not well versed with it, so I can only offer you the resource:

http://www.salesforce.com/us/developer/docs/api_analytics/

1
  • thx bro :) i will look into it :) – eassa May 18 '15 at 6:28

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.