0

I have created controller and vf page.In my controller having three buttons such as modify,save and cancel.when i click the modify button(read only) it display the same page with save and cancel button.when i select the picklist value it will be updated in account object.when i click the save button i am getting this error ;

System.QueryException: List has no rows for assignment to SObject Error is in expression '{!Submit}' in component in page rfleet_paymetcondition: Class.Rfleet_PaymentConditions.Submit: line 38, column 1.

How can i resolve this issue. please find below attached images controller and vf page

enter image description here enter image description here

Vf Page:

 <apex:page standardController="account" extensions="Rfleet_PaymentConditions" showHeader="false" sidebar="false">
    <apex:form > 

        <apex:pageBlock >
            <apex:pageBlockButtons location="bottom" >
                    <apex:commandbutton value="Modify" action="{!save}" rendered="{!showSave}"  />
                    <apex:commandbutton value="Save" action="{!Submit}" rendered="{!showSubmit}"/>
                    <apex:commandbutton value="Cancel" action="{!Back}" rendered="{!showback}"/>
            </apex:pageBlockButtons> 


    <apex:panelGrid columns="2" width="100%" html-readonly="true">  

<!-------------------- Start Period1 Section---------------------------------------->

   <apex:pageblock title="Period 1" id="blockA" >
    <apex:outputPanel id="otpn">
    <apex:outputLabel ><b>Upper Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></apex:outputLabel>
 <apex:inputField value="{!acc.Rfleet_UpperDate_Period1__c}" html-disabled="{!bool}" id="acctype"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <script>document.getElementById('{!$Component.acctype}').disabled = {!bool}; </script>
        <apex:inputField value="{!account.Rfleet_UpperMonth_Period1__c}" html-disabled="{!bool}" id="acctype1"/><br/><br/>
         <script>document.getElementById('{!$Component.acctype1}').disabled = {!bool}; </script>

    <apex:outputLabel ><b>Lower Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></apex:outputLabel>
        <apex:inputField value="{!account.Rfleet_LowerDate_Period1__c}" html-disabled="{!bool}" id="acctype2"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
         <script>document.getElementById('{!$Component.acctype2}').disabled = {!bool}; </script>
        <apex:inputField value="{!account.Rfleet_LowerMonth_Period1__c}" html-disabled="{!bool}" id="acctype3"/><br/><br/>
         <script>document.getElementById('{!$Component.acctype3}').disabled = {!bool}; </script>

   <apex:outputLabel ><b>Due Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></apex:outputLabel> 
         <apex:inputField value="{!account.Rfleet_DueDate_Period1__c}" html-disabled="{!bool}" id="acctype4"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <script>document.getElementById('{!$Component.acctype4}').disabled = {!bool}; </script>
         <apex:inputField value="{!account.Rfleet_DueMonth_Period1__c}" html-disabled="{!bool}" id="acctype5"/>
          <script>document.getElementById('{!$Component.acctype5}').disabled = {!bool}; </script>
   </apex:outputPanel>      
   </apex:pageBlock> 


  <apex:pageblock title="Period 2" id="blockB">
  <apex:outputPanel id="otpn1">
    <apex:outputLabel ><b> Upper Date &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></apex:outputLabel>
         <apex:inputField value="{!account.Rfleet_UpperDate_Period2__c}" html-disabled="{!bool}" id="acctype6"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <script>document.getElementById('{!$Component.acctype6}').disabled = {!bool}; </script>
         <apex:inputField value="{!account.Rfleet_UpperMonth_Period2__c}" html-disabled="{!bool}" id="acctype7"/><br/><br/>
          <script>document.getElementById('{!$Component.acctype7}').disabled = {!bool}; </script>

   <apex:outputLabel ><b>Lower Date &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></apex:outputLabel>
         <apex:inputField value="{!account.Rfleet_LowerDate_Period2__c}" html-disabled="{!bool}" id="acctype8"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <script>document.getElementById('{!$Component.acctype8}').disabled = {!bool}; </script>
         <apex:inputField value="{!account.Rfleet_LowerMonth_Period2__c}" html-disabled="{!bool}" id="acctype9"/><br/><br/>
          <script>document.getElementById('{!$Component.acctype9}').disabled = {!bool}; </script>

   <apex:outputLabel ><b>Due Date &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></apex:outputLabel> 
         <apex:inputField value="{!account.Rfleet_DueDate_Period2__c}" html-disabled="{!bool}" id="acctype10"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
           <script>document.getElementById('{!$Component.acctype10}').disabled = {!bool}; </script>
         <apex:inputField value="{!account.Rfleet_DueMonth_Period2__c}" html-disabled="{!bool}" id="acctype11"/>
           <script>document.getElementById('{!$Component.acctype11}').disabled = {!bool}; </script>
   </apex:outputPanel>
   </apex:pageBlock> 

     </apex:panelGrid>

    </apex:pageBlock> 

   </apex:form>
</apex:page>

Controller:

public class Rfleet_PaymentConditions {

 public Boolean bool {get;set;} public Boolean showSave{get;set;}
 public Boolean showSubmit{get;set;} public Boolean showback{get;set;}
 public string id; public account acc{get;set;}

     public Rfleet_PaymentConditions(ApexPages.StandardController controller) {
         bool = true;
        showSave = true;
          id=ApexPages.currentPage().getParameters().get('id');
     }
       public void save() {

     bool =false;
     showSave=false;
     showSubmit=true;
     showback=true;

     }  public PageReference back() {    // PageReference newocp = new PageReference('/apex/RFLEET_PaymetCondition');    //
 newocp.setredirect(true);
     PageReference pageRef = new PageReference('/' + ApexPages.currentPage().getParameters().get('id')+'?inline=0');
     return pageRef;
    //return newocp;  } 


  public void Submit() {  
bool=false;   
acc=[SELECT
 Rfleet_DueDate_Period1__c,Rfleet_DueDate_Period2__c,Rfleet_DueMonth_Period1__c,Rfleet_DueMonth_Period2__c,Rfleet_LowerDate_Period1__c,Rfleet_LowerDate_Period2__c,Rfleet_LowerMonth_Period1__c,Rfleet_LowerMonth_Period2__c,Rfleet_UpperDate_Period1__c,Rfleet_UpperDate_Period2__c,Rfleet_UpperMonth_Period1__c,Rfleet_UpperMonth_Period2__c
 FROM Account where id=:id];   insert acc;  
}     
}
0

The Submit method in controller doesnt look logical. Checkout these two contradicting lines -

    acc=[SELECT Rfleet_DueDate_Period1__c, Rfleet_DueDate_Period2__c, Rfleet_DueMonth_Period1__c,
Rfleet_DueMonth_Period2__c,Rfleet_LowerDate_Period1__c,Rfleet_LowerDate_Period2__c,
Rfleet_LowerMonth_Period1__c,Rfleet_LowerMonth_Period2__c,Rfleet_UpperDate_Period1__c,
Rfleet_UpperDate_Period2__c,Rfleet_UpperMonth_Period1__c,Rfleet_UpperMonth_Period2__c
 FROM Account where id=:id]; 

AND

  insert acc; 

Now the 1st line, you are querying account object, which essentially means that you are expecting the Account to be present in the database. In the second line you are trying to insert the same account into the database which is already present.

Currently the error comes because this query (1st line) is not returning any row back from database due to missing ID parameter in the URL. Checkout this line where you get ID from the URL.

id=ApexPages.currentPage().getParameters().get('id');

But be ensured, even if you fix this error, you might get an error in the next line. i.e. insert acc;

So its important to revisit on what functionality is expected and accordingly align both these lines.You might also want to look at this answer : How do I start to debug my own Apex code?

  • hi Amit Bangad,i follow your suggestions,but finally i got a error like: Visualforce Error Help for this Page System.QueryException: List has no rows for assignment to SObject Error is in expression '{!Submit}' in component <apex:commandButton> in page rfleet_paymetcondition: Class.Rfleet_PaymentConditions.Submit: line 39, column 1 Class.Rfleet_PaymentConditions.Submit: line 39, column 1. can u please solve the issue – kiran k Aug 10 '15 at 12:29
  • The exception is still the same, Can you check if ID is being passed in the URL ? then can you also apply system.debugs and see if you are getting value in 'id'? – Amit Bangad Aug 10 '15 at 12:31
  • can you check is it correct i mention id in query....acc=[SELECT Rfleet_DueDate_Period1__c, Rfleet_DueDate_Period2__c, Rfleet_DueMonth_Period1__c, Rfleet_DueMonth_Period2__c,Rfleet_LowerDate_Period1__c,Rfleet_LowerDate_Period2__c, Rfleet_LowerMonth_Period1__c,Rfleet_LowerMonth_Period2__c,Rfleet_UpperDate_Period1__c, Rfleet_UpperDate_Period2__c,Rfleet_UpperMonth_Period1__c,Rfleet_UpperMonth_Period2__c FROM Account where id='001m000000Kf3Qf']; – kiran k Aug 10 '15 at 12:36

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.