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
Lukesh KarmoreLukesh Karmore 

Vf page is not updating account

i am new to visualforce i created a page with customController that shows list of account and i want to update account  field within the list below is my code ,so any one please let me know where is the mistake
its not updating field

public class CustomController {
    list<account> acts;
    
    public list<account> getacts(){
        acts=new list<account>();
       acts=[select name,rating,industry,type from account where rating!=null AND type!=null limit 20];
        return acts;
    }
    public pageReference save(){
        update acts;
        return null;
    }
}

<apex:page  Controller="CustomController">
 <apex:form >
 <apex:pageBlock title="Account Display">
     <apex:pageBlockButtons location="bottom">
     <apex:commandButton value="save" action="{!save}"/>
     </apex:pageBlockButtons>
     <apex:pageMessages />
 <apex:pageBlockSection >
 <apex:pageBlockTable value="{!acts}" var="c">
 <apex:column value="{!c.name}"/>
 <apex:column value="{!c.rating}"/>
 <apex:column value="{!c.Industry}"/>
 <apex:column value="{!c.type}"/>
 </apex:pageBlockTable>
     <apex:inlineEditSupport />
 </apex:pageBlockSection>
 </apex:pageBlock>
 </apex:form>
</apex:page>
Thank You
ANUTEJANUTEJ (Salesforce Developers) 
Hi Lukesh,

>> https://developer.salesforce.com/forums/?id=9060G0000005eLUQAY

The above link has an implementation to update an account record via visualforce page, below is the controller class that is mentioned you can modify it to fit your need.
 
public class OppAccupdateController 
{
    public Account Acc {get;set;}
    public Opportunity Opp;
    public string errormessage {get;set;}
    public OppAccupdateController(Apexpages.StandardController controller)
    {
        opp = (Opportunity)controller.getRecord();
        ID accid = [select AccountID from Opportunity where ID=:opp.Id].AccountID;
        if(accid!=null)
        {
        acc = [select id,Website, Project_Manager__c, Account_Director__c, Account_Manager__c from account where ID=:accid]; // specify the list of fields after type seperated by comma from account that you have used in VF page 
        }
    }
    
    public void Accsave()
    {
     try{
        update acc;
        }catch(Exception e)
        {
        system.debug('exception'+' '+ e.getMessage());
        errormessage = e.getMessage();
        }
    }
    
}

Let me know if it helps you and close your query by marking it as the best answer so that it can help others in the future.  

Thanks.
Lukesh KarmoreLukesh Karmore
No not helpful , I want to know where  is the error in my code it helps me to improve