+ Start a Discussion
vanessa veronvanessa veron 

Using Visualforce value of the future

hello...
is it possible to use a informed value in a Visualforce page in future?

For example I inform an email and I will use this email to JOB schedule ....

Are you doing this?
How do I?

Thank you

global class ASchedTeste implements System.Schedulable {
public String str{get;set;}
public String mail{get;set;}
public String nomJob{get;set;}

global void execute(SchedulableContext sc) {
  newPublier();
}

//Cria bem o job na hora informada 0 28 15 * * ?
public void schedulejob(){
        String NomJobSchedulable = nomJob;
        ASchedTeste p = new ASchedTeste();
        String sch = str; 
        system.schedule(NomJobSchedulable , sch, p);    
}

public void newPublier(){

List<case> acclist = [Select casenumber,subject, accountid from case limit 10];
string header = 'Id, Subject,Account, '+'\n';
string finalstr = header ;
for(case a: acclist)
{
   string recordString = a.casenumber + ',' + a.subject+ ',' + a.accountid +'\n';
   finalstr = finalstr + recordString;
}
Messaging.EmailFileAttachment csvAttc = new Messaging.EmailFileAttachment();
blob csvBlob = Blob.valueOf(finalstr);
string csvname= 'cases.csv';
csvAttc.setFileName(csvname);
csvAttc.setBody(csvBlob);
Messaging.SingleEmailMessage email =new Messaging.SingleEmailMessage();
String[] toAddresses = new list<string> {mail};
String subject = 'Report CSV';
email.setSubject(subject);
email.setToAddresses( toAddresses );
email.setPlainTextBody('Informations HERE');
email.setFileAttachments(new Messaging.EmailFileAttachment[]{csvAttc});
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
  }   
}

--------------------------------------------------------------------------------------------------------------------

<apex:page controller="ASchedTeste">
  <apex:form >
  <apex:PageBlock >
    :::::::::: TEST TEST TEST :::::::::: <br /><br />  
    Mail..........:&nbsp;<apex:inputText styleClass="classeMail" value="{!mail}"/><br /><br />
    Nom Job.......:&nbsp;<apex:inputText styleClass="classeMail" value="{!nomJob}"/><br /><br />
    Plan.....:<apex:inputText value="{!str}" />
    <apex:commandButton value="Schedule" action="{!schedulejob}" />
   
  </apex:PageBlock>
  </apex:form>
</apex:page>
Best Answer chosen by vanessa veron
PatlatusPatlatus

Try to pass this parameter through constructor and store them in global instance property.

So, change mail property directive from public to global

public String mail{get;set;} => global String mail{get;set;}

Then try to change method

public void schedulejob( String email ){

        String NomJobSchedulable = nomJob;

        ASchedTeste p = new ASchedTeste( email );

        String sch = str;

        system.schedule(NomJobSchedulable , sch, p);  

}

 

global ASchedTeste( String email ){
     mail = email;
}

Hope this would help

All Answers

PatlatusPatlatus

As far as I understand, you are trying to use email selected on visualforce page inside schedule job execute method.

I think you could try to pass this parameter through constructor and store them in global instance property.

vanessa veronvanessa veron
that's what I want to do, use the email address entered in the Visualforce page.
And how do I do it?
THANK YOU
PatlatusPatlatus

Try to pass this parameter through constructor and store them in global instance property.

So, change mail property directive from public to global

public String mail{get;set;} => global String mail{get;set;}

Then try to change method

public void schedulejob( String email ){

        String NomJobSchedulable = nomJob;

        ASchedTeste p = new ASchedTeste( email );

        String sch = str;

        system.schedule(NomJobSchedulable , sch, p);  

}

 

global ASchedTeste( String email ){
     mail = email;
}

Hope this would help

This was selected as the best answer
vanessa veronvanessa veron
I will try,

thank you so much...
vanessa veronvanessa veron
It worked!

Thank you so much....

Have a nice weekend!
PatlatusPatlatus

I'm glad this helped to you.

I provided the same answer to other guys here http://salesforce.stackexchange.com/a/26928/3716 but nobody even voted my answer there