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
Vaibhav DesaleVaibhav Desale 

vf page help...unable to save record in backend

I am new to salesforce... please help... I have requirement like: one custom object Employee having three field Name,Account,Contact. Now I am creating a vf page with this three fields... but when I am saving my record from vf only employyee name is reflected. it is showing account and contact blank. And also i want to go redirect at record page which i am creating through vf when saved.
vf and controller as follows
vf 
<apex:page StandardController="EmployeeA__c" extensions="classes" >
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlock title="Employee Page">
                <apex:PageBlockSection >
                    <apex:inputText value="{!Name}"/>
                    <apex:inputField value="{!EmployeeA__c.Account__c}"/>
                    <apex:inputField value="{!EmployeeA__c.Contact__c}"/>
                </apex:PageBlockSection> 
                <apex:pageBlockSection >
                    <apex:commandButton value="Save" action="{!Save}"/>
                    <apex:commandButton value="Cancel" action="{!Cancel}"/>
                </apex:pageBlockSection>
            </apex:pageBlock>
        </apex:pageBlock>
    </apex:form>
</apex:page>

controller

public with sharing class classes {

    public String Name { get; set; }

    public  String Account {get; set;}
    
    public String Contact {get; set;}
    
   

     
      VAD03__EmployeeA__c objdlt;
     private ApexPages.StandardController controller;
    public classes(ApexPages.StandardController controller) {
    this.controller = controller;
    

    }

public PageReference save() {
        /*
        VAD03__EmployeeA__c objdlt = new VAD03__EmployeeA__c();
        objdlt.Name=Name;
        objdlt.VAD03__Account__c=Account;
        objdlt.VAD03__Contact__c=Contact;
        insert objdlt;
        */
        controller.cancel();   
        PageReference congratsPage = Page.Congratulations;
        congratsPage.setredirect(true);
        return congratsPage;
    }
    
        public PageReference Cancel() {
            
            controller.cancel(); // This takes care of the details for you.
            PageReference congratsPage = Page.Congratulations;
            congratsPage.setRedirect(true);
            return congratsPage;
}
}
 
Best Answer chosen by Vaibhav Desale
VamsiVamsi
Based on the value of Account and contact entered by user retrieve those records using soql to get record id and then provide them to below fields objdlt.VAD03__Account__c= Pass account ID ; objdlt.VAD03__Contact__c= Pass contact ID;

All Answers

VamsiVamsi
If account and contact are lookup fields on Employee then you need to provide Account and Contact ID's respectively by retrieving those records from account and contact.

Please mark as best answer if the above helps ..!!!
Vaibhav DesaleVaibhav Desale
Hi..
Thanks for reply....can u please tell me how to do this?
VamsiVamsi
Based on the value of Account and contact entered by user retrieve those records using soql to get record id and then provide them to below fields objdlt.VAD03__Account__c= Pass account ID ; objdlt.VAD03__Contact__c= Pass contact ID;
This was selected as the best answer
Vaibhav DesaleVaibhav Desale
Thank you Vamsi. It worked...!! 
 
VamsiVamsi
Please mark as best answer if the above helps. So that it would be helpfull for others