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
adi salesforceadi salesforce 

How to create a button edit for list of account records and if we click the edit it should open edit page

SHAHNA MULLASHAHNA MULLA
Hi,
Try this code :

VFP :
<apex:page Controller="Redirect_Main2" action="{!Redirect_Main}">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockTable value="{!accs}" var="a" >
                <apex:column value="{!a.Id}"/>
                <apex:column value="{!a.Name}"/>
                <apex:column value="{!a.Phone}"/>
                <apex:column value="{!a.Industry}"/>
                <apex:column id="two">
                    <apex:commandButton value=" Edit " onclick="window.open('/{!a.id}/e?retURL={!a.id}')" reRender="two"/>
            </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Controller : 
public class Redirect_Main2 {

   public List<Account> accs { get; set; }
    public PageReference Redirect_Main(){
        accs = [select id,name,phone,Industry from account];       
        return null;
     }
}

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!
PINKY REGHUPINKY REGHU
Hi,
Try this code
Vf:
<apex:page Controller="accsearchcontroller1" >
    <apex:form >
     <apex:pageBlock> 
            <apex:selectList value="{!acid}" multiselect="false" size="1">
                <apex:selectOptions value="{!AccountNames1}" />
	</apex:selectList>
            <apex:commandButton value="Edit" action="{!editbutton}"/>
           </apex:pageBlock>  
    </apex:form>
     
</apex:page>
controller:
public with sharing class accsearchcontroller1 { 
public Account accs ;
    public List<selectOption> AccountNames{get;set;}
    public String acid{get;set;}
    public  accsearchcontroller1(){
       }
    public List<selectOption> getAccountNames1() {
        AccountNames = new List<selectOption>();
        AccountNames.add(new selectOption('--none--','--none--'));
		for(Account accs:[select id,name,phone,Industry from Account]) 
		{  
    			String sobjid = String.valueOf(accs.id);
				String sobjName = String.valueOf(accs.name);
				AccountNames.add(new selectOption(sobjid,sobjName));
		}
		return AccountNames;
    }
    public PageReference editbutton(){
        System.debug('AccountNames: ' + acid);
        Id i = Id.valueOf(acid);
        System.debug(i);
       	return new PageReference('/'+i+'/e?retURL=/'+i);
    }
}