Skip to content

Instantly share code, notes, and snippets.

@martyychang
Created December 12, 2014 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save martyychang/a3e6cefa272e3dd716a1 to your computer and use it in GitHub Desktop.
Save martyychang/a3e6cefa272e3dd716a1 to your computer and use it in GitHub Desktop.
Demonstration of how apex:actionSupport and apex:param are supposed to work together
<apex:page controller="ActionSupportParamDemoController">
<apex:form>
<apex:repeat value="{!accounts}" var="account">
<apex:inputCheckbox value="{!account.IsActive__c}">
<apex:actionSupport event="onchange"
action="{!handleAccountCheckboxChange}">
<apex:param id="account" name="accountId" value="{!account.Id}"
assignTo="{!targetAccountId}"/>
</apex:actionSupport>
</apex:inputCheckbox>
{!account.Name}
</apex:repeat>
</apex:form>
Selected: {!selectedAccountId}
</apex:page>
public class ActionSupportParamDemoController {
private Id targetAccountId;
public Id selectedAccountId { get; set; }
public List<Account> getAccounts() {
return [
SELECT Id, Name, Website, IsActive__c
FROM Account
];
}
public Id getTargetAccountId() {
return targetAccountId;
}
public PageReference handleAccountCheckboxChange() {
System.debug('targetAccountId: ' + targetAccountId);
selectedAccountId = targetAccountId;
return null;
}
public void setTargetAccountId(Id value) {
targetAccountId = value;
}
}
@anik2131
Copy link

anik2131 commented Apr 6, 2021

I am getting null as AccountId... Can you please verify

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment