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
Alessandro Guarnieri 4Alessandro Guarnieri 4 

Add an action using Standard List Controller

Hi,

I'm trying to add the save action to a button on a visualforce page to save a new account. I'm using a standard list controller because I want the page to be available as a list button. If I click on save it doesn't work, am I missing something?

Thanks

Here is the code:
<apex:page standardController="Account" recordSetVar="accounts">
   <apex:form>
       <apex:pageBlock>

       <apex:pageBlockSection>
       
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Account Name</apex:outputLabel>
                <apex:inputField id="actName" value="{!account.name}"/>
            </apex:pageBlockSectionItem>     
           
       		<apex:commandButton value="Save" action="{!save}"/>
           
       </apex:pageBlockSection>
           
       </apex:pageBlock>           
   </apex:form>
</apex:page>

 
Alessandro Guarnieri 4Alessandro Guarnieri 4
Hi piyush,

thanks for the reply, unfortunately it doesn't really work if I add <apex:pageBlockButtons> </apex:pageBlockButtons>. Do you have any other suggestions?

Thanks,
Alessandro
Alessandro Guarnieri 4Alessandro Guarnieri 4
Yes in this case it works but unfortunately I need the standard list controller.

Thanks
Alessandro Guarnieri 4Alessandro Guarnieri 4
Thanks for the explanation. I need to use recordsetvar because I want this page to be available as a list button, that's why I need to add recordsetvar. So in order to use the save button should I use a controller extension and write a save method there? It would be nice if you could help me witrh that!

thanks,

Alessandro
Ragava reddyRagava reddy
Hi,

Pleace check the below code,I think it will works for u 

<apex:page standardController="Account" recordSetVar="accounts">
   <apex:form >
       <apex:pageblock >
        <apex:pageBlockTable value="{!accounts}" var="acc">
            <apex:column headerValue="Name">
            <apex:inputField value="{!acc.name}"/>
            </apex:column>
           <!-- <apex:column headerValue="Name">
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:column> -->
        </apex:pageBlockTable>
       <apex:commandButton value="Save" action="{!save}"/>
        </apex:pageblock>
   </apex:form>
</apex:page>

Thanks,
Raghavendra Reddy.D
 
Alessandro Guarnieri 4Alessandro Guarnieri 4
Thanks for the code Ragava,

my goal would be to have a visualforce page which I can use on a custom list button to override the new button and to create a new account, so this solution doesn't really fit unfortunately. It would be nice then to write a method on a controller extension which saves the new account, since the save action of the standard list controller doesn't work in my case. 

Alessandro
Ragava reddyRagava reddy
You have to check the below code,

public class recordsetvarsavecon {
    Public Account accobj{get;set;}
    public recordsetvarsavecon(ApexPages.StandardSetController controller) {
        accobj= new Account();
    }
    
    Public void save(){
        Account acc=new Account();
        acc.Name=accobj.Name;
        insert acc;
    }

}

<apex:page standardController="Account" extensions="recordsetvarsavecon" recordSetVar="accounts">
   <apex:form >
       <apex:pageblock >
            <apex:inputField value="{!accobj.name}"/>
       <apex:commandButton value="Save" action="{!save}"/>
        </apex:pageblock>
   </apex:form>
</apex:page>

Thanks,
Raghavendra Reddy