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
sfdc98sfdc98 

vf and apex

Hi everyone ,i need to display list of account records with a button beside  the records when i click on that button it should open a contact form and able to save the record.
tried so far..

class:
public class Displayrecs {
   public String firstName{get;set;}
    public String lastName{get;set;}
    public String phone{get;set;}
    //list <contact> conList;
     public ApexPages.StandardSetController stdCntrlr {get; set;}

 
    
    public Displayrecs(ApexPages.StandardSetController controller){
        stdCntrlr = controller;
    }
    
    public pageReference Save(){
        Contact con = new Contact(firstname=firstname, lastname=lastname, phone=phone);
        //conList.add(con);
        insert con;
        return null; 
   }
}

vf:
<apex:page standardController="Account" recordSetVar="accounts" extensions="Displayrecs" >
    <apex:form>
        <apex:pageBlock>
             <apex:pageBlockTable value="{!accounts}" var="a" id="list">
        <apex:column value="{!a.name}"/>
                 <apex:column value="{!a.rating}"/>
                 <apex:column>
                     <apex:commandButton action="{!save}" value="save"/>
                 </apex:column>
      </apex:pageBlockTable>
            
        </apex:pageBlock>
       
         
    </apex:form>
</apex:page>

User-added imageable to view like above screenshot.
Thanks in Advance
SwethaSwetha (Salesforce Developers) 
HI,
Where exactly are you stuck? Thx
sfdc98sfdc98
Hi swetha thanks for the reply,when i click on save button i need to open contact form ,but am getting error required fields is missing lastname.

Thanks