0

Good day I am having the error shown below:

List has no rows for assignment to SObject : Error is in expression '{!UpdateRecord}' in component

I am trying to update the lead record with the respective fields.

The record id is being passed on the page url as highlighted below: https://c.org.visual.force.com/apex/MyPage?id=00Q2XXXX001XXXX

My Visual Force page has a submit button shown below:

<apex:commandButton styleClass="submit" value="Submit    Application" action="{!UpdateRecord}"/>

Apex Controller

 public class MyPageController
 {
  public Lead leadDetail 
  {get;set;}
  public Id leadId
  {get;set;}
  //attachment Document name
  public string businessDocName 
  {get;set;}
  //attachment Document body
  public Blob documentBody 
  {get;set;} 
  //attachment ID name
  public string idCardName 
  {get;set;}
  //attachment ID body
  public Blob idCardBody 
  {get;set;} 
   //get the lead id record
   public MyPageController(ApexPages.StandardController ctlr)
     {
      leadId = ctlr.getRecord().Id;     
  }
   //update the fields on the record 
   public PageReference UpdateRecord(){
  Id leadId ;
  //lead custom fields and definitions 
  leadDetail = [SELECT Customer_Name__c, Licence_c, Email_c, Surname_and_First_Name__c, Job_Title__c, Telephone_Number__c FROM Lead WHERE Id  =: leadid];

  PageReference pgRef;
  if((documentBody != null && businessDocName != null)||(idCardBody !=   null && idCardName != null))
  {
      Attachment businessDocument  = new Attachment();
      Attachment idDocument  = new Attachment();
       if(documentBody != null && businessDocName != null)
      {
          businessDocument.Body = documentBody;
          businessDocument.Name = businessDocName;
          businessDocument.ParentId = leadId;
          try
         {
              if(idCardBody != null && idCardName != null)
              { 
                  idDocument.Body = idCardBody;
                  idDocument.Name = idCardName;
                  idDocument.ParentId = leadId;
              }
              insert businessDocument;
              insert idDocument;
          }catch(DMLException e)
          {
              ApexPages.addMessage(new   ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
                  return null;
          }
      }
      pgRef = new PageReference('http://thank.you/');
      pgRef.setRedirect(true);
      return pgRef;
  }   
  return null;
  }    
}

What am I missing and how can I resolve it? Thank you in advance for the assistance.

1
  • leadId doesn't have any value thats why you are getting error.... just remove this Id leadId ; from UpdateRecord method
    – Ratan Paul
    Aug 22 '16 at 13:09
0

Seems there is a miss match between variable naming convention. As updateRecord() method also had leadId variable. You need to remove leadId variable from updateRecord() method.

2
  • @user23 - If that worked can you please mark this answer as the correct answer so the question does not keep appearing as unanswered and so other having a similar question can find answers...
    – Eric
    Aug 22 '16 at 13:59
  • 1
    thanks @Eric sorry the system had asked me to wait a while before marking the answer.
    – user23
    Aug 22 '16 at 14:25

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.