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
rebvijkumrebvijkum 

System.HttpResponse[Status=Bad Request, StatusCode=400]

My Code:
trigger Send_PDF_to_SharePointhelp on QNews__c (after insert, after update) {
    for(QNews__c qn: Trigger.new){    
        SendVFAsAttachment.sendVF('vijaku@xxx.com','Sample Test from Trigger','Sample Email Body',UserInfo.getSessionId(),qn.Article_ID__c); 
    }
}





public class SendVFAsAttachment{

    @future(callout=true)
    public static void sendVF(String EmailIdCSV, String Subject,String body,String userSessionId, ID articleid)
    {
        system.debug('====================6=====');
        //Replace below URL with your Salesforce instance host
        String addr = 'https://xxx--kmbuild.cs10.my.salesforce.com/services/apexrest/sendPDFEmail';
        HttpRequest req = new HttpRequest();
        req.setEndpoint( addr );
        req.setMethod('POST');
        req.setHeader('Authorization', 'OAuth ' + userSessionId);
        req.setHeader('Content-Type','application/json');

        Map<String,String> postBody = new Map<String,String>();
        postBody.put('EmailIdCSV',EmailIdCSV);
        postBody.put('Subject',Subject);
        postBody.put('body',body);
        postBody.put(articleid,articleid);
        String reqBody = JSON.serialize(postBody);

        req.setBody(reqBody);
        Http http = new Http();
        HttpResponse response = http.send(req);
    }
}




@RestResource(urlMapping='/sendPDFEmail/*')
Global class GETPDFContent{
     @HttpPost
    global static void sendEmail(String EmailIdCSV, String Subject, String body,ID articleid) {

    List<String> EmailIds = EmailIdCSV.split(',');
        system.debug('====================7=====articleid:'+articleid);
        PageReference ref = Page.Multi_Topic_PDF;
        ref.getParameters().put('id',(String)articleid); 
            ref.setRedirect(true);
        Blob b = ref.getContentAsPDF();
        system.debug('====================10====blob:'+b);
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

        Messaging.EmailFileAttachment efa1 = new Messaging.EmailFileAttachment();
        efa1.setFileName('attachment_WORK.pdf');
        efa1.setBody(b);

        String addresses;
        email.setSubject( Subject +String.valueOf(DateTime.now()));
        email.setToAddresses(EmailIds);
        email.setPlainTextBody(Body);
        email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa1});
        Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});

    }
}
Best Answer chosen by rebvijkum
rebvijkumrebvijkum
Thanks for reply, i solved the issue, The  articleid in postmethod is an Id, it supposed to be string.

All Answers

EnreecoEnreeco
Do u have a namespace defined in your org?
Do u see any debugging from the webservice (I mean can u see if the webservice throws an exception?)
rebvijkumrebvijkum
Thanks for reply, i solved the issue, The  articleid in postmethod is an Id, it supposed to be string.
This was selected as the best answer