+ Start a Discussion
hacksawblade16hacksawblade16 

passing parameters from VF to controller

can somebody give me an example for passing boolean value from jquery in a visual force page to controller using param and action function.I'm getting this error after executing the following code...

Error: conversionTrialController Compile Error: Illegal assignment from String to Boolean at line 393 column 9

<apex:includeScript value="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"/>

 

 <script type="text/javascript">

        var j$ = jQuery.noConflict();       

        j$(document).ready(function(){

   }); 

 

 

function orgChkBoxesSelected()

        {

var orgName=j$('#chk_org_name').is(":checked");

alert(orgName);

var orgAddr=j$('#chk_org_addr').is(":checked");

         

          getorgCheckedBox(orgName,orgAddr)       

        } 

         

 

 

 

<apex:actionFunction name="getorgCheckedBox" action="{!getCheckedOrgBoxes}" reRender="orgBlock">

 <Apex:param name="orgNames" value=""/>

 <Apex:param name="orgAddrs" value="" />

<Apex:actionFunction/>

 

 

 

public void getCheckedOrgBoxes()

 {

Boolean org_Name=Apexpages.currentPage().getParameters().get('orgNames');----------->>>>line 393 column 9

Boolean org_Addr=Apexpages.currentPage().getParameters().get(‘orgAddrs’);

 

organization=leadUtility.getorganization(org_Name,org_Addr);

     return NULL;     

Best Answer chosen by Admin (Salesforce Developers) 
Rahul SharmaRahul Sharma

You could check if the String returns 'True' or 'False', then assign corresponsing value to Boolean variable.

Like done below:

 

public void getCheckedOrgBoxes()
{
	String OrgName = Apexpages.currentPage().getParameters().get('orgNames');
	String OrgAddr = Apexpages.currentPage().getParameters().get('orgAddrs');
	
	Boolean org_Name;
	if( OrgName == 'True') {
		org_Name = True;
	}
	else {
		org_Name = False;
	}

	Boolean org_Addr;
	if( orgAddr == 'True') {
		org_Addr = True;
	}
	else {
		org_Addr = False;
	}
}

  Or other way would be:

public void getCheckedOrgBoxes()
{
	String OrgName = Apexpages.currentPage().getParameters().get('orgNames');
	String OrgAddr = Apexpages.currentPage().getParameters().get('orgAddrs');
	
	Boolean org_Name = False;
	if( OrgName == 'True') {
		org_Name = True;
	}

	Boolean org_Addr = False;
	if( orgAddr == 'True') {
		org_Addr = True;
	}
}

 

All Answers

Rahul SharmaRahul Sharma

Use a string variable to collect the param's as their datatype is String.

 

Try modifying your code as below:

String org_Name=Apexpages.currentPage().getParameters().get('orgNames');
String org_Addr=Apexpages.currentPage().getParameters().get('orgAddrs');

 

hacksawblade16hacksawblade16
Thank you,But Can't I get boolean values back??as you see i'm passing them in the method getOrganization.(org_name,org_addr);.I need to pass it as boolean in that method.
Rahul SharmaRahul Sharma

You could check if the String returns 'True' or 'False', then assign corresponsing value to Boolean variable.

Like done below:

 

public void getCheckedOrgBoxes()
{
	String OrgName = Apexpages.currentPage().getParameters().get('orgNames');
	String OrgAddr = Apexpages.currentPage().getParameters().get('orgAddrs');
	
	Boolean org_Name;
	if( OrgName == 'True') {
		org_Name = True;
	}
	else {
		org_Name = False;
	}

	Boolean org_Addr;
	if( orgAddr == 'True') {
		org_Addr = True;
	}
	else {
		org_Addr = False;
	}
}

  Or other way would be:

public void getCheckedOrgBoxes()
{
	String OrgName = Apexpages.currentPage().getParameters().get('orgNames');
	String OrgAddr = Apexpages.currentPage().getParameters().get('orgAddrs');
	
	Boolean org_Name = False;
	if( OrgName == 'True') {
		org_Name = True;
	}

	Boolean org_Addr = False;
	if( orgAddr == 'True') {
		org_Addr = True;
	}
}

 

This was selected as the best answer
hacksawblade16hacksawblade16
Thank You :)I got it