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
Paul AllsoppPaul Allsopp 

Set commandButton action in code

I have a code component that dynamically creates a series of buttons based on a range of values, so just to be clear, NOT apex markup!
Everything works fine, but I need to add an action to the buttons and this is where I am having issue. In apex markup I would add a actionSupport tag to point back to a custom controller method, however, how is this achieved in code?
 
ApexPages.Action ap_action = new ApexPages.Action([what goes here?])
my_button.action = ap_action; // this will fail once the page is rendered

Any help is greatly appreciated.
Paul
Paul AllsoppPaul Allsopp
I had forgotten to mention, when I do the above, I get: Invalid value for property action: argument type mismatch 
Which seems odd to me, because I am creating an action, and assigning it to a property of an object, and the type for that property is an ApexPages.Action.

Here is my actual code:
Component.Apex.ActionSupport as_action = new Component.Apex.ActionSupport();
as_action.event = 'onclick';
as_action.action = new ApexPages.Action('searchByLetter');

And in my controller:
public PageReference searchByLetter(String letter) {
    	String letter_like_query = 'SELECT Id, Name FROM Account WHERE Name LIKE "%' + letter + '"';
 	   	List<Account> results = Database.query(letter_like_query);
        for (Account acc : results) {
            this.companies.add(acc);
        }
        
        return null;
    }


Any thoughts on what is wrong here?
Paul