2
<apex:page standardController="Employee__c" extensions="testPage" id="p">
<apex:form id="f">



    <div>
        <input type="radio" name="acc" value="Existing" checked="checked"
                onclick="show(true, false);">Existing</input>
        <input type="radio" name="acc" value="NEWAcc"
                onclick="show(false, true);">New</input>
    </div>
    <apex:pageBlock id="pb1" title="Pg Block 1">
    <apex:pageBlockButtons >
 <apex:commandButton value="save" action="{!saving}"/>
   </apex:pageBlockButtons>

   <apex:pageBlockSection columns="1">
   <apex:inputField value="{!pme.Name}" />
   <apex:inputField value="{!pme.Address__c}"/>
      <apex:inputField value="{!pme.Phone__c}"/>
<apex:inputField value="{!pme.type__c}"/>

   </apex:pageBlockSection>
    </apex:pageBlock>
    <apex:pageBlock id="pb2" title="Pg Block 2">
    <apex:pageBlockButtons >
 <apex:commandButton value="save" action="{!saving}"/>
  </apex:pageBlockButtons>

   <apex:pageBlockSection columns="1">
   <apex:inputField value="{!pme.Name}" />
<apex:inputField value="{!pme.Job_Title__c}"/>
   <apex:inputField value="{!pme.Salary__c}"/>
   <apex:inputField value="{!pme.type__c}"/>

   </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>   
<script>
function show(showPb1, showPb2) {
    // Match Visualforce's prefixing pattern
    document.getElementById('p:f:pb1').style.display = showPb1 ? 'block' : 'none';
    document.getElementById('p:f:pb2').style.display = showPb2 ? 'block' : 'none';
}
show(true, false);
</script>
</apex:page>

Controller

public with sharing class testPage {
public string Existing{get; set;}
public string NEWAcc{get; set;}
public Boolean radioexisting{get; set;}
public Boolean radionew{get; set;}
public Employee__c pmepme{get;set;}
List<SelectOption> ownershipValues;
    public Employee__c emp{get;set;}
    public Employee__c pme{get;set;}
    public Employee__c emplist{get;set;}
    public String var {get;set;}
        public boolean editSection {get;set;}

        public testPage(ApexPages.StandardController controller) {
        radioexisting=true;
        radionew=false;
            Employee__c emp=new Employee__c();
            pme=(Employee__c )controller.getRecord();
            editSection =true;
            var= ApexPages.currentPage().getParameters().get('Id');
             system.debug('erecrrrtrtrt');

                system.debug('erecrrrtrtrt'+NEWAcc);
            if(var!=null){
            emplist=[select Name,Address__c,Phone__c,Job_Title__c,Salary__c,type__c  From Employee__c where id=:var];
            }
            }

        public PageReference saving(){
                        system.debug('erecrrrtrtrt'+Existing);

                system.debug('erecrrrtrtrt'+NEWAcc);
            upsert pme;
            PageReference p=new PageReference ('/'+pme.id);
            p.setRedirect(true);
            return p;
            }
    public PageReference pbBlockRender() {
    return null;
    }
    public PageReference EdittheSection (){
editSection = true;
PageReference pf=new PageReference('https://c.ap2.visual.force.com/apex/test6');

pf.setredirect(true);
return pf;


        }

    public String mypbBlock { get; set; }
}

iam getting the following please help to fix it

System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Employee__c.Name

1

What you can try to do:

  1. Try to use the addFields() method of the StandardController class. That will explicitly add fields to the record:
public testPage(ApexPages.StandardController controller) {
    ...
    controller.addFields(new String[]{'Id','Name'});
    this.pme = (Employee__c )controller.getRecord();
  1. Use this. if initializing an variable from the standard controller in constructor:
this.pme = (Employee__c )controller.getRecord();


I hope this helps!

2
  • this.pme = (Employee__c )controller.getRecord(); using this i got it,,,thanq
    – Satya
    Mar 23 '16 at 9:47
  • @sahi Ok, you are welcome! Mar 23 '16 at 10:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.