I am trying to build an utility to bulk publish documents through apex HTTPCallout. I dont want to read individual files from some visualforce page as this not feasible for bulk publishes. Rather want to be able to just provide URL and the files get sent through HTTPCallout. I tried this with Postman for one single document and it did work. Just trying to put the same but for mulitple documents in an apex code. Kindly suggest.

public void publish(){
    if(UserInfo.getSessionId() != null) {
        Http h = new Http();
        HttpRequest req = new HttpRequest();
        req.setHeader('Content-Type', 'multipart/form-data');
        req.setTimeout((Integer) settings.My_Timeout_MVN__c);
        req.setHeader('Authorization', '5F055E6F00EA0JHKH98Y8989');
        String body = 'file= C:\\ignore\\ignore\\Downloads\\my sample document.docx'
            +'& type__v = type1'
            +'& name__v = Document from Utility'
            +'& summary__c = Summary of Doc';
        req.setHeader('Accept', 'application/json');
        try {
            HttpResponse res = h.send(req);
        }catch(Exception e) {
  • 1
    You should remove your authorization code from the question, and invalidate it.
    – David Reed
    Jan 2 '18 at 20:01
  • Thank You. I did take care of that. It's just a combination of some random letters and numbers. :) Jan 2 '18 at 20:05

Enrico Murru has provided a brilliant solution for this Salesforce problem. Please find the path below.


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.