+ Start a Discussion
rebvijkumrebvijkum 

Error: Compile Error: Variable does not exist: ref

I wanted to use if condition, but in order to do that i need to remove static keyword, but Http method are supposed to be static.
How can i solve this???


@RestResource(urlMapping='/sendPDFEmail/*')
Global class GETPDFContent{
     @HttpPost
    global static void sendEmail(String EmailIdCSV, String Subject, String body,string newID,string attachmentfilename,string ArticleTitle,string ArticleType) {
    List<String> EmailIds = EmailIdCSV.split(',');
        if(ArticleType=='Multi_Topic_PDF__kav'){
            PageReference ref = Page.Multi_Topic_PDF; 
          }
 
   
            ref.getParameters().put('id',newID); 
            ref.setRedirect(true);
        Blob b = ref.getContentAsPDF();


        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

        Messaging.EmailFileAttachment efa1 = new Messaging.EmailFileAttachment();
        efa1.setFileName(attachmentfilename);
        efa1.setBody(b);

        String addresses;
        email.setSubject( Subject );
        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
pconpcon
Your problem is not the static keyword, it is the scope of your ref variable
 
@RestResource(urlMapping='/sendPDFEmail/*')
Global class GETPDFContent {
    @HttpPost
    global static void sendEmail(String EmailIdCSV, String Subject, String body, string newID, string attachmentfilename, string ArticleTitle, string ArticleType) {
        List<String> EmailIds = EmailIdCSV.split(',');

        PageReference ref = Page.MyDefaultPage;

        if (ArticleType=='Multi_Topic_PDF__kav') {
            ref = Page.Multi_Topic_PDF; 
        }       

        ref.getParameters().put('id',newID); 
        ref.setRedirect(true);

        Blob b = ref.getContentAsPDF();

        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

        Messaging.EmailFileAttachment efa1 = new Messaging.EmailFileAttachment();
        efa1.setFileName(attachmentfilename);
        efa1.setBody(b);

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

    }
}

In this code you will need to update Page.MyDefaultPage to be something so that you do not get an Null Pointer Exception when you call getParameters

All Answers

pconpcon
Your problem is not the static keyword, it is the scope of your ref variable
 
@RestResource(urlMapping='/sendPDFEmail/*')
Global class GETPDFContent {
    @HttpPost
    global static void sendEmail(String EmailIdCSV, String Subject, String body, string newID, string attachmentfilename, string ArticleTitle, string ArticleType) {
        List<String> EmailIds = EmailIdCSV.split(',');

        PageReference ref = Page.MyDefaultPage;

        if (ArticleType=='Multi_Topic_PDF__kav') {
            ref = Page.Multi_Topic_PDF; 
        }       

        ref.getParameters().put('id',newID); 
        ref.setRedirect(true);

        Blob b = ref.getContentAsPDF();

        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

        Messaging.EmailFileAttachment efa1 = new Messaging.EmailFileAttachment();
        efa1.setFileName(attachmentfilename);
        efa1.setBody(b);

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

    }
}

In this code you will need to update Page.MyDefaultPage to be something so that you do not get an Null Pointer Exception when you call getParameters
This was selected as the best answer
venkat rajvenkat raj
Variable does not exist: TOMORROW ,what are the date format for tomorrow's(Ex., today date format is date.today())
pconpcon
You can do
 
Date.today().addDays(1);

That will show tomorrow