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
vanessa veronvanessa veron 

visualforce action with parameters

Hello!!!

Is it possible to pass parameters / args in Visualforce Page?

Thank you!!!
PAGE:

<apex:pageBlockTable value="{!jobRecords}" var="ac">
              <apex:column headervalue="Name Job" value="{!ac.CronJobDetail.Name}"/>
                <apex:column headervalue="Status" value="{!ac.State}"/>
                <apex:column headervalue="Expression" value="{!ac.CronExpression}"/>
                <apex:column> <apex:commandButton value="X" action="{!deleteJob('NAMEEE')}"/></apex:column>
              </apex:pageBlockTable> 

APEX:

public void deleteJob(String nameJob) {
    idJobDel= new List<CronTrigger>();
    idJobDel= [SELECT  Id FROM CronTrigger where CronJobDetail.Name =: nameJob];
    System.abortJob(idJobDel[0].id);
   }

Best Answer chosen by vanessa veron
Ramesh KallooriRamesh Kalloori
Please find the below code.

use strJobName as property of the class.

public String strJobName {get;set;}
<apex:page controller="DelAccount" >
  <apex:form >
  <apex:pageBlock >
  <apex:actionFunction action="{!DelAcc}" name="methodOneInJavascript" rerender="showstate" reRender="pb">
        <apex:param name="firstParam" assignTo="{!DelID}" value="" />
    </apex:actionFunction>

  <apex:pageBlockTable value="{!Ac}" var="a" id="pb">
  <apex:column HeaderValue="Name" value="{!a.Name}"/>
  <apex:column headerValue="Del">
      <apex:outputPanel onclick="methodOneInJavascript('{!a.id}')" styleClass="btn"> 
        Del 
    </apex:outputPanel>
  </apex:column>
  </apex:pageBlockTable>
  </apex:pageBlock>
  </apex:form>
</apex:page>
public class DelAccount {

    public PageReference DelAcc() {
    Account delA=[Select ID from Account where ID=:DelID];
    Delete delA;
        return null;
    }
public String DelID{get;set;}
public List<Account> Ac{get{
List<Account> a=[Select ID,Name from Account limit 100];
return a;
}set;}
}

thanks,
Ramesh

All Answers

Ramesh KallooriRamesh Kalloori
yes we can use param tag.
PAGE:

<apex:pageBlockTable value="{!jobRecords}" var="ac">
              <apex:column headervalue="Name Job" value="{!ac.CronJobDetail.Name}"/>
                <apex:column headervalue="Status" value="{!ac.State}"/>
                <apex:column headervalue="Expression" value="{!ac.CronExpression}"/>
                <apex:column> <apex:commandLink action="{!deleteJob}" value="X">
 <apex:param name="h" value="{!ac.id}" assignTo="{!nameJob}"/>
 </apex:commandLink></apex:column>
              </apex:pageBlockTable> 

APEX:

public void deleteJob(String nameJob) {
public String nameJob{get;set;}
    idJobDel= new List<CronTrigger>();
    idJobDel= [SELECT  Id FROM CronTrigger where CronJobDetail.Name =: nameJob];
    System.abortJob(idJobDel[0].id);
   }
thanks,
Ramesh
Rehan DeveloperRehan Developer

Hi Vanessa,

Yes it is possible to pass parameters to Apex Class from Visualforce Page.

You will need to create following points :
1. Public String strJobName {get;set;}

2. Action function on visualforce page.

3. On apex:commandbutton remove action attribute and have onclick attribute.
 

PAGE:

<apex:actionfunction name="callDeleteJob" action="deleteJob" rerender="pbBlockTable">
<apex:param name="JobName" value="" assignTo="{!strJobName}" />
</apex:actionFunction>
 
<apex:pageBlockTable value="{!jobRecords}" var="ac" id="pbBlockTable">
              <apex:column headervalue="Name Job" value="{!ac.CronJobDetail.Name}"/>
                <apex:column headervalue="Status" value="{!ac.State}"/>
                <apex:column headervalue="Expression" value="{!ac.CronExpression}"/>
                <apex:column> <apex:commandButton value="X" onClick="callDeleteJob('{!ac.CronJobDetail.Name}')"/></apex:column>
              </apex:pageBlockTable> 

APEX:
public String strJobName {get;set;}

// In Constructor, please initialize this variable "strJobName"  otherwise it will give you an error for "Attempt to de-reference null"

public void deleteJob() {
if(strJobName != '')
{
    idJobDel= new List<CronTrigger>();
    idJobDel= [SELECT  Id FROM CronTrigger where CronJobDetail.Name =: strJobName];
    System.abortJob(idJobDel[0].id);
}
else
{
system.debug('I didn't receive the value Job Name');
}
   }

I hope this will provide answer for your question.

Please let me know your response.

Thanks

 

vanessa veronvanessa veron
Thank you ly friends...

Rehan Developer, It didn't work:
The job is not deleted as desired!!!
public String strJobName {get;set;}

//CONSTRUTOR:
global Class() {strJobName='';}

public void deleteJob() {
if(strJobName != '')
{
    idJobDel= new List<CronTrigger>();
    idJobDel= [SELECT  Id FROM CronTrigger where CronJobDetail.Name =: strJobName];
    System.abortJob(idJobDel[0].id);
   }
   else
{
system.debug('Pas de Nom');
}
}

PAGE:

          <apex:actionfunction name="callDeleteJob" action="deleteJob" rerender="pbBlockTable">
              <apex:param name="JobName" value="" assignTo="{!strJobName}" />
          </apex:actionFunction>
          
          <apex:pageBlockTable value="{!jobRecords}" var="ac" id="pbBlockTable">
              <apex:column headervalue="Nom de la Tâche" value="{!ac.CronJobDetail.Name}"/>
                <apex:column headervalue="Status" value="{!ac.State}"/>
                <apex:column headervalue="Expression" value="{!ac.CronExpression}"/>
                
                <apex:column><apex:commandButton value="X" onClick="callDeleteJob('{!ac.CronJobDetail.Name}')"/> </apex:column>
                  
              </apex:pageBlockTable>

vanessa veronvanessa veron
Any tip?
Ramesh KallooriRamesh Kalloori
Please find the below code.

use strJobName as property of the class.

public String strJobName {get;set;}
<apex:page controller="DelAccount" >
  <apex:form >
  <apex:pageBlock >
  <apex:actionFunction action="{!DelAcc}" name="methodOneInJavascript" rerender="showstate" reRender="pb">
        <apex:param name="firstParam" assignTo="{!DelID}" value="" />
    </apex:actionFunction>

  <apex:pageBlockTable value="{!Ac}" var="a" id="pb">
  <apex:column HeaderValue="Name" value="{!a.Name}"/>
  <apex:column headerValue="Del">
      <apex:outputPanel onclick="methodOneInJavascript('{!a.id}')" styleClass="btn"> 
        Del 
    </apex:outputPanel>
  </apex:column>
  </apex:pageBlockTable>
  </apex:pageBlock>
  </apex:form>
</apex:page>
public class DelAccount {

    public PageReference DelAcc() {
    Account delA=[Select ID from Account where ID=:DelID];
    Delete delA;
        return null;
    }
public String DelID{get;set;}
public List<Account> Ac{get{
List<Account> a=[Select ID,Name from Account limit 100];
return a;
}set;}
}

thanks,
Ramesh

This was selected as the best answer
vanessa veronvanessa veron
Thank you!!!!
Ramesh KallooriRamesh Kalloori
if it works make it as best answer going forther it will useful to others.

thanks,
Ramesh
vanessa veronvanessa veron
I will try this solutions before =D