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
apple_saeapple_sae 

Passing Parameters to Apex Method from Visualforce Page to update records

Dear Expert,

I am trying to Pass parameter to Apex method from VF page.It work for remove But i am not able to get the parameter value for update.

 

<apex:repeat value="{!lstAuthContacts}" var="AC">
 <apex:form >
 <apex:commandLink value="Remove" action="{!removeContact}">
   <apex:param name="delContact" value="{!AC.Id}" assignTo="{!cParam}"></apex:param>
 </apex:commandLink>

<label>First name*</label>
<apex:inputField value="{!AC.FirstName}" styleClass="form-text" id="form-text-contact-first-name"/>

<label>Last name*</label>
<apex:inputField value="{!AC.LastName}" styleClass="form-text" id="form-text-contact-last-name"/>
<label>Phone*</label>
<apex:inputField value="{!AC.Phone}" styleClass="form-text" id="form-text-contact-phone"/>
<label>Email address*</label>
<apex:inputField value="{!AC.Email}" styleClass="form-text" id="form-text-contact-email"/>

<apex:commandButton action="{!updateAuthContact}" value="Save updates" id="theButton"> <apex:param name="updateContact" value="{!AC.Id}" assignTo="{!cParam}"></apex:param> </apex:commandButton>
</apex:form>
</apex:repeat>

 

 

public with sharing class AccountProfileController {
public Id aid {get;set;}
public string cParam{get;set;} public list<Contact> lstAuthContacts{get;set;} public AccountProfileController(){ getlstAuthContacts(); } private void getlstAuthContacts(){ aid = Apexpages.currentPage().getParameters().get('id'); if(aid != ''){ lstAuthContacts = [Select Contact.Id, Contact.Name, Contact.Contact_Type__c, Contact.FirstName, Contact.LastName, Contact.Phone, Contact.Email, Contact.MailingStreet, Contact.MailingCity, Contact.MailingState, Contact.MailingPostalCode, Contact.MailingCountry, Contact.Living_Will__c From Contact Where Contact.AccountId = :aid And Contact.Contact_Type__c = 'Authorized Contact']; } }
public PageReference removeContact(){
if(cParam != ''){
Contact toDel=new Contact(id=cParam);
delete todel;
getlstAuthContacts
}
returm null;
}
public PageReference updateAuthContact() {
if(cParam != ''){
Contact toUpdate=new Contact(id=cParam);
update toUpdate;
getlstAuthContacts();
}
return null;
}
}



bob_buzzardbob_buzzard

I've found that parameters don't get passed unless the commandbutton has a rerender attribute - I've always assumed this means it needs to be an Ajax request to send the parameters.

 

If I don't have anything to sensibly rerender, I just put an outputpanel around the entire content and rerender that.

apple_saeapple_sae

I have do like this it's still not working

<apex:repeat value="{!lstAuthContacts}" var="AC">
 <apex:outputPanel id="lstAuthContacts">
  <apex:form >
  <apex:commandLink value="Remove" action="{!removeContact}">
    <apex:param name="delContact" value="{!AC.Id}" assignTo="{!cParam}"></apex:param>
  </apex:commandLink>
			 
  <label>First name*</label>
  <apex:inputField value="{!AC.FirstName}" styleClass="form-text" id="form-text-contact-first-name"/>
  
<label>Last name*</label> <apex:inputField value="{!AC.LastName}" styleClass="form-text" id="form-text-contact-last-name"/> <label>Phone*</label> <apex:inputField value="{!AC.Phone}" styleClass="form-text" id="form-text-contact-phone"/> <label>Email address*</label> <apex:inputField value="{!AC.Email}" styleClass="form-text" id="form-text-contact-email"/> <apex:commandButton action="{!updateAuthContact}" value="Save updates" id="theButton" rerender="lstAuthContacts">
<apex:param name="updateContact" value="{!AC.Id}" assignTo="{!cParam}"> </apex:param> </apex:commandButton>
</apex:form>
</apex:outputPanel>
</apex:repeat>
GsajeeshGsajeesh
<apex:repeat value="{!lstAuthContacts}" var="AC">

  <apex:form >
  <apex:commandLink value="Remove" action="{!removeContact}">
    <apex:param name="delContact" value="{!AC.Id}" assignTo="{!cParam}"></apex:param>
  </apex:commandLink>
			 
  <label>First name*</label>
  <apex:inputField value="{!AC.FirstName}" styleClass="form-text" id="form-text-contact-first-name"/>
  
<label>Last name*</label> <apex:inputField value="{!AC.LastName}" styleClass="form-text" id="form-text-contact-last-name"/> <label>Phone*</label> <apex:inputField value="{!AC.Phone}" styleClass="form-text" id="form-text-contact-phone"/> <label>Email address*</label> <apex:inputField value="{!AC.Email}" styleClass="form-text" id="form-text-contact-email"/> <apex:commandButton action="{!updateAuthContact}" value="Save updates" id="theButton" rerender="lstAuthContacts">
<apex:param name="updateContact" value="{!AC.Id}" assignTo="{!cParam}"> </apex:param> </apex:commandButton>
<apex:pageBlock rendered="false" id="lstAuthContacts"></apex:pageBlock>
</apex:form>

</apex:repeat>

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

apple_saeapple_sae

Hi Gsajeesh

 

Thank you for your help, I have tried it's not work.

 

ValnavjoValnavjo

Hello apple_sae,

 

Try this in your "updateAuthContact()" controller method:

 

final String cParam = ApexPages.currentPage().getParameters().get('updateContact');

If it works, you can delete the "assignTo" attribute. 

 

 

Regards,

 

JVN

GsajeeshGsajeesh

U also have to define proper getters and setters for this in your controller

 

Thanks!

dphilldphill

Try rerendering something that is within your <apex:form> tags