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
Sami ShakithSami Shakith 

SObject row was retrieved via SOQL without querying the requested field: Interrogate__c.X1__c Error is in expression '{!save1}' in component <apex:commandButton> in page apstest: Class.ApsTestController.save1: line 40, column 1

Hi,

I dont know why my page shows this error. Please give a solution. My VF page is like as below


<apex:page standardController="Interrogate__c" extensions="ApsTestController">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                1. A compiler converts the Java program into an intermediate language representation called ____________.<br></br>
                         <apex:selectradio >
                          <apex:selectOptions value="{!X1optionsbelow}"/><br></br><br></br>
                           </apex:selectradio>
                        
                       2. _____________ operator is used to create an object.<br></br>
                            <apex:selectradio >
                           <apex:selectOptions value="{!x2optionsbelow}"/>
                           </apex:selectradio>
                       
            </apex:pageBlockSection>
                <apex:pageBlockButtons location="bottom">
                 <apex:commandButton value="Finish" action="{!save1}" />
                </apex:pageBlockButtons>
        </apex:pageBlock>    
    </apex:form>
</apex:page>

My controller class is as below:

public class ApsTestController{
public Interrogate__c Interrogate{get;set;}
public string x1{get;set;}
public string x2{get;set;}
public string id{get;set;}
public List<SelectOption> x1optionsbelow{get;set;}
public List<SelectOption> x2optionsbelow{get;set;}
public ApsTestcontroller(apexpages.standardcontroller controller)

{


Interrogate = new Interrogate__c();
interrogate = (interrogate__c)controller.getrecord();
x1optionsbelow=new List<SelectOption>();
Schema.DescribeFieldResult statusFieldDescription1=Interrogate__c.X1__c.getDescribe();
        for (Schema.Picklistentry picklistEntry:statusFieldDescription1.getPicklistValues()){
        x1optionsbelow.add(new SelectOption(pickListEntry.getValue(),pickListEntry.getLabel()));
            if (picklistEntry.defaultValue){
            Interrogate.X1__c= pickListEntry.getValue();
            }  
         } 
x2optionsbelow=new List<SelectOption>();
Schema.DescribeFieldResult statusFieldDescription=Interrogate__c.X2__c.getDescribe();
        for (Schema.Picklistentry picklistEntry:statusFieldDescription.getPicklistValues()){
        x2optionsbelow.add(new SelectOption(pickListEntry.getValue(),pickListEntry.getLabel()));
            if (picklistEntry.defaultValue){
            Interrogate.X2__c= pickListEntry.getValue();
            }  
         } 

}
public pagereference save1()

    {
        interrogate__c inte=new interrogate__c();
        inte = [select id, name, name__c, X1__c, X2__c from interrogate__c where id=:Interrogate.id];
        inte.X1__c = Interrogate.X1__c;
        inte.x2__c = Interrogate.x2__c;
        upsert inte;
        pagereference ref;
        ref = new pagereference('/apex/ApsTest?id='+interrogate.id);
        ref.setredirect(true);
        return ref;
    }
}

I want to update the X1 and X2 feilds in interrogate object. But it is not updating.
Best Answer chosen by Sami Shakith
SaranSaran
If thats the case I hope you have to change the VF page also

Below is the Page:-
<apex:page standardController="Interrogate__c" extensions="ApsTestController">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                1. A compiler converts the Java program into an intermediate language representation called ____________.<br></br>
                         <apex:selectradio value="{!x1Answer}">
                          <apex:selectOptions value="{!X1optionsbelow}"/><br></br><br></br>
                           </apex:selectradio>
                        
                       2. _____________ operator is used to create an object.<br></br>
                            <apex:selectradio value="{!x2Answer}">
                           <apex:selectOptions value="{!x2optionsbelow}"/>
                           </apex:selectradio>
                       
            </apex:pageBlockSection>
                <apex:pageBlockButtons location="bottom">
                 <apex:commandButton value="Finish" action="{!save1}" />
                </apex:pageBlockButtons>
        </apex:pageBlock>    
    </apex:form>
</apex:page>

this is the controller 
 
public class ApsTestController{
public Interrogate__c Interrogate{get;set;}
public string x1{get;set;}
public string x2{get;set;}
public string id{get;set;}
public List<SelectOption> x1optionsbelow{get;set;}
public List<SelectOption> x2optionsbelow{get;set;}
public ApsTestcontroller(apexpages.standardcontroller controller)
public string x1Answer{get;set;}
public string x2Answer{get;set;}
{


Interrogate = new Interrogate__c();
interrogate = (interrogate__c)controller.getrecord();
x1optionsbelow=new List<SelectOption>();
Schema.DescribeFieldResult statusFieldDescription1=Interrogate__c.X1__c.getDescribe();
        for (Schema.Picklistentry picklistEntry:statusFieldDescription1.getPicklistValues()){
        x1optionsbelow.add(new SelectOption(pickListEntry.getValue(),pickListEntry.getLabel()));
            if (picklistEntry.defaultValue){
            Interrogate.X1__c= pickListEntry.getValue();
            }  
         } 
x2optionsbelow=new List<SelectOption>();
Schema.DescribeFieldResult statusFieldDescription=Interrogate__c.X2__c.getDescribe();
        for (Schema.Picklistentry picklistEntry:statusFieldDescription.getPicklistValues()){
        x2optionsbelow.add(new SelectOption(pickListEntry.getValue(),pickListEntry.getLabel()));
            if (picklistEntry.defaultValue){
            Interrogate.X2__c= pickListEntry.getValue();
            }  
         } 

}
public pagereference save1()

    {
        interrogate__c inte=new interrogate__c();
        inte = [select id, name, name__c, X1__c, X2__c from interrogate__c where id=:Interrogate.id];
        inte.X1__c = x1Answer;
        inte.x2__c = x2Answer;
        update inte;
        pagereference ref;
        ref = new pagereference('/apex/ApsTest?id='+interrogate.id);
        ref.setredirect(true);
        return ref;
    }
}

Hope this works fine!!

Thanks

All Answers

Keyur  ModiKeyur Modi
Hi,
You can try below code ,
public class ApsTestController{
public Interrogate__c Interrogate{get;set;}
public string x1{get;set;}
public string x2{get;set;}
public string id{get;set;}
public List<SelectOption> x1optionsbelow{get;set;}
public List<SelectOption> x2optionsbelow{get;set;}
public ApsTestcontroller(apexpages.standardcontroller controller)

{


Interrogate = new Interrogate__c();
interrogate = (interrogate__c)controller.getrecord().id;
x1optionsbelow=new List<SelectOption>();
interrigate =[SELECT id, name, name__c, X1__c, X2__c FROM interrogate__c WHERE id=:Interrogate.id ];
Schema.DescribeFieldResult statusFieldDescription1=Interrogate__c.X1__c.getDescribe();
        for (Schema.Picklistentry picklistEntry:statusFieldDescription1.getPicklistValues()){
        x1optionsbelow.add(new SelectOption(pickListEntry.getValue(),pickListEntry.getLabel()));
            if (picklistEntry.defaultValue){
            Interrogate.X1__c= pickListEntry.getValue();
            }  
         } 
x2optionsbelow=new List<SelectOption>();
Schema.DescribeFieldResult statusFieldDescription=Interrogate__c.X2__c.getDescribe();
        for (Schema.Picklistentry picklistEntry:statusFieldDescription.getPicklistValues()){
        x2optionsbelow.add(new SelectOption(pickListEntry.getValue(),pickListEntry.getLabel()));
            if (picklistEntry.defaultValue){
            Interrogate.X2__c= pickListEntry.getValue();
            }  
         } 

}
public pagereference save1()

    {
        interrogate__c inte=new interrogate__c();
        inte.id = Interrogate.id;
        inte.X1__c = Interrogate.X1__c;
        inte.x2__c = Interrogate.x2__c;
        upsert inte;
        pagereference ref;
        ref = new pagereference('/apex/ApsTest?id='+interrogate.id);
        ref.setredirect(true);
        return ref;
    }
}


Here i made two changes one is i deed query "
interrigate =[SELECT id, name, name__c, X1__c, X2__c FROM interrogate__c WHERE id=:Interrogate.id ];
"
at line 40 and removed the query from save1() method.

Please let me know if this will help,

Thanks,
Keyur Modi


 
Sami ShakithSami Shakith
it shows an error while saving class.  Incompatible types since an instance of Id is never an instance of Interrogate__c at line 14 column 15
Keyur  ModiKeyur Modi
Hi,
please use this code,
 
public class ApsTestController{
private interrogate__c interro;
public Interrogate__c Interrogate{get;set;}
public string x1{get;set;}
public string x2{get;set;}
public string id{get;set;}
public List<SelectOption> x1optionsbelow{get;set;}
public List<SelectOption> x2optionsbelow{get;set;}
public ApsTestcontroller(apexpages.standardcontroller controller)

{


Interrogate = new Interrogate__c();
this.interro=(interrogate__c)controller.getrecord();
x1optionsbelow=new List<SelectOption>();
interrigate =[SELECT id, name, name__c, X1__c, X2__c FROM interrogate__c WHERE id=:interro.id ];
Schema.DescribeFieldResult statusFieldDescription1=Interrogate__c.X1__c.getDescribe();
        for (Schema.Picklistentry picklistEntry:statusFieldDescription1.getPicklistValues()){
        x1optionsbelow.add(new SelectOption(pickListEntry.getValue(),pickListEntry.getLabel()));
            if (picklistEntry.defaultValue){
            Interrogate.X1__c= pickListEntry.getValue();
            }  
         } 
x2optionsbelow=new List<SelectOption>();
Schema.DescribeFieldResult statusFieldDescription=Interrogate__c.X2__c.getDescribe();
        for (Schema.Picklistentry picklistEntry:statusFieldDescription.getPicklistValues()){
        x2optionsbelow.add(new SelectOption(pickListEntry.getValue(),pickListEntry.getLabel()));
            if (picklistEntry.defaultValue){
            Interrogate.X2__c= pickListEntry.getValue();
            }  
         } 

}
public pagereference save1()

    {
        interrogate__c inte=new interrogate__c();
        inte.id = Interrogate.id;
        inte.X1__c = Interrogate.X1__c;
        inte.x2__c = Interrogate.x2__c;
        upsert inte;
        pagereference ref;
        ref = new pagereference('/apex/ApsTest?id='+interrogate.id);
        ref.setredirect(true);
        return ref;
    }
}


please let me know, if this will help.

Thanks,
Keyur Modi
Sami ShakithSami Shakith
Record not saving in the object modi.
Thanks for your reply modi. 
Sami ShakithSami Shakith
Record not saving in object saraz
Sami ShakithSami Shakith
yeah rite.
SaranSaran
If thats the case I hope you have to change the VF page also

Below is the Page:-
<apex:page standardController="Interrogate__c" extensions="ApsTestController">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                1. A compiler converts the Java program into an intermediate language representation called ____________.<br></br>
                         <apex:selectradio value="{!x1Answer}">
                          <apex:selectOptions value="{!X1optionsbelow}"/><br></br><br></br>
                           </apex:selectradio>
                        
                       2. _____________ operator is used to create an object.<br></br>
                            <apex:selectradio value="{!x2Answer}">
                           <apex:selectOptions value="{!x2optionsbelow}"/>
                           </apex:selectradio>
                       
            </apex:pageBlockSection>
                <apex:pageBlockButtons location="bottom">
                 <apex:commandButton value="Finish" action="{!save1}" />
                </apex:pageBlockButtons>
        </apex:pageBlock>    
    </apex:form>
</apex:page>

this is the controller 
 
public class ApsTestController{
public Interrogate__c Interrogate{get;set;}
public string x1{get;set;}
public string x2{get;set;}
public string id{get;set;}
public List<SelectOption> x1optionsbelow{get;set;}
public List<SelectOption> x2optionsbelow{get;set;}
public ApsTestcontroller(apexpages.standardcontroller controller)
public string x1Answer{get;set;}
public string x2Answer{get;set;}
{


Interrogate = new Interrogate__c();
interrogate = (interrogate__c)controller.getrecord();
x1optionsbelow=new List<SelectOption>();
Schema.DescribeFieldResult statusFieldDescription1=Interrogate__c.X1__c.getDescribe();
        for (Schema.Picklistentry picklistEntry:statusFieldDescription1.getPicklistValues()){
        x1optionsbelow.add(new SelectOption(pickListEntry.getValue(),pickListEntry.getLabel()));
            if (picklistEntry.defaultValue){
            Interrogate.X1__c= pickListEntry.getValue();
            }  
         } 
x2optionsbelow=new List<SelectOption>();
Schema.DescribeFieldResult statusFieldDescription=Interrogate__c.X2__c.getDescribe();
        for (Schema.Picklistentry picklistEntry:statusFieldDescription.getPicklistValues()){
        x2optionsbelow.add(new SelectOption(pickListEntry.getValue(),pickListEntry.getLabel()));
            if (picklistEntry.defaultValue){
            Interrogate.X2__c= pickListEntry.getValue();
            }  
         } 

}
public pagereference save1()

    {
        interrogate__c inte=new interrogate__c();
        inte = [select id, name, name__c, X1__c, X2__c from interrogate__c where id=:Interrogate.id];
        inte.X1__c = x1Answer;
        inte.x2__c = x2Answer;
        update inte;
        pagereference ref;
        ref = new pagereference('/apex/ApsTest?id='+interrogate.id);
        ref.setredirect(true);
        return ref;
    }
}

Hope this works fine!!

Thanks
This was selected as the best answer
Sami ShakithSami Shakith
Thanks for reply saraz. but it shows error like this 
Error: Compile Error: unexpected token: 'public' at line 9 column 0
Sami ShakithSami Shakith
Thanks a lot :) its working.