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
StephenJacobGoldbergStephenJacobGoldberg 

can't get param from vforce page to apex method

I have a command button, and when I try and use it in the visualforce page I am not able to reterive the paramter from the page, it returns null

 

Here is the visualforce code

 

 

<apex:page standardController="Account" extensions="Controller_DupeChecker">
<apex:form >
<apex:dataTable value="{!DupeAccounts}" var="das" width="100%" border="1px" style="text-align:center">
<apex:column headerValue="Account Names" value="{!das.Name}"/>
<apex:column headerValue="Phone" value="{!das.Phone}"/>
<apex:column headerValue="Shipping Street" value="{!das.ShippingStreet}"/>
<apex:column headerValue="Billing Street" value="{!das.BillingStreet}"/>
<apex:column >
<apex:commandButton action="{!MergeAccounts}" value="Merge" id="theButton">
<apex:param name="acid" value="{!das.id}"/>
</apex:commandButton>
</apex:column>
<apex:column >{!das.id}</apex:column>
</apex:dataTable>

</apex:form>
</apex:page>

 

 

 

 

And here is the apex class

 

	public PageReference MergeAccounts(){
	// aid is not passing a value 	
	Id aid = System.currentPageReference().getParameters().get('acid');
	
	List<Account> mergeAccounts = new List<Account>();
	system.debug('aid: '  + aid);
	
	Account mergeAccount = ([select Id FROM Account WHERE Id =:aid]);
	//merge function doesn't bring over fields
	merge acc mergeAccount;
	return null;
	}

 

 

Please help!

 

Best Answer chosen by Admin (Salesforce Developers) 
GobbledigookGobbledigook

When you call {!DupeAccount}, is the Data showing correctly in the Data Table itself, or is it returning null values?  If they're all returning null values, try Skodisana's response


Additionally:  There have been reports of a bug with the CommandButton and the getter, setter methods for a while now.  Just for testing, try switching to a command Link and give it a shot.  

 

Off the top of my head, the code is something like this:

 

 

<apex:commandLink action="{!MergeAccount}" value="Merge" > <apex:param tag here> </apex:commandLink>

 

A better explanation of the bug (and ways to work around it) can be found here:

 

http://blog.jeffdouglas.com/2010/03/04/passing-parameters-with-a-commandbutton/

 

Best of luck.

 

 

All Answers

skodisanaskodisana

Hi,

 

Delete the 3rd line in the visualforcepage code and replace with below code:

 

<apex:dataTable value="{!mergeAccountList}" var="das" width="100%" border="1px" style="text-align:center">

Please use the below controller code

 

public PageReference MergeAccounts(){
// aid is not passing a value
Id aid = System.currentPageReference().getParameters().get('acid');

List<Account> mergeAccountsList = new List<Account>();
system.debug('aid: ' + aid);

mergeAccountList = ([select Id,Name,Phone,ShippingStreet,BillingStreet FROM Account WHERE Id =:aid]);
//merge function doesn't bring over fields
//merge acc mergeAccount;
return null;
}



StephenJacobGoldbergStephenJacobGoldberg

Skodisana, 

 

Thanks for the quick reply, but I don't see how that will solve the problem... 

GobbledigookGobbledigook

When you call {!DupeAccount}, is the Data showing correctly in the Data Table itself, or is it returning null values?  If they're all returning null values, try Skodisana's response


Additionally:  There have been reports of a bug with the CommandButton and the getter, setter methods for a while now.  Just for testing, try switching to a command Link and give it a shot.  

 

Off the top of my head, the code is something like this:

 

 

<apex:commandLink action="{!MergeAccount}" value="Merge" > <apex:param tag here> </apex:commandLink>

 

A better explanation of the bug (and ways to work around it) can be found here:

 

http://blog.jeffdouglas.com/2010/03/04/passing-parameters-with-a-commandbutton/

 

Best of luck.

 

 

This was selected as the best answer
StephenJacobGoldbergStephenJacobGoldberg

Thanks Gobbledigook, that worked perfectly.  My data in the table was fine, thats why I was confused by the other comment. 

 

Stephen 

sravusravu
<apex:page standardController="Account" extensions="Controller_DupeChecker">
<apex:form >
<apex:dataTable value="{!DupeAccounts}" var="das" width="100%" border="1px" style="text-align:center">
<apex:column headerValue="Account Names" value="{!das.Name}"/>
<apex:column headerValue="Phone" value="{!das.Phone}"/>
<apex:column headerValue="Shipping Street" value="{!das.ShippingStreet}"/>
<apex:column headerValue="Billing Street" value="{!das.BillingStreet}"/>
<apex:column >
<apex:commandLink action="{!MergeAccounts}" value="Merge" id="theButton">
<apex:param name="acid" value="{!das.id}" assignTo="{!dasId}"/>
</apex:commandLink>
</apex:column>
<apex:column >{!das.id}</apex:column>
</apex:dataTable>

</apex:form>
</apex:page>
StephenJacobGoldbergStephenJacobGoldberg

sravu,

 

Thanks for trying ...but that doesn't work either the other solution provided actually works.