• SREENIVASULU.C
  • NEWBIE
  • 15 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 7
    Replies
Apex:
public with sharing class inlinecontroller {
Public contact conRec{get;set;}
Public id accRecId;
Public account accRec{get;set;}
    public inlinecontroller(ApexPages.StandardController controller) {    
     accRecId = [select id,accountid from contact where id=:ApexPages.currentPage().getParameters().get('id')].accountid;
      if(accRecId != null)
      {
         accRec = [select id,name,accountnumber,annualrevenue from account where id =:accRecId];
         }
    }
}

Visualforce:

<apex:page standardController="contact" extensions="inlinecontroller">
<apex:form >
   <apex:pageBlock title="My Inline Visualforce page">
    Account Name <apex:outputField value="{!accRec.name}"/><br/>
     Account Number  <apex:outputField value="{!accRec.accountnumber}"/><br/>
     Annual Revenue  <apex:outputField value="{!accRec.annualrevenue}"/><br/>
   </apex:pageBlock>
</apex:form>
</apex:page>
Error:

Visualforce Error
Help for this Page

System.QueryException: List has no rows for assignment to SObject
Class.inlinecontroller.<init>: line 6, column 1
Apex:
public with sharing class inlinecontroller {
Public contact conRec{get;set;}
Public id accRecId;
Public account accRec{get;set;}
    public inlinecontroller(ApexPages.StandardController controller) {    
     accRecId = [select id,accountid from contact where id=:ApexPages.currentPage().getParameters().get('id')].accountid;
      if(accRecId != null)
      {
         accRec = [select id,name,accountnumber,annualrevenue from account where id =:accRecId];
         }
    }
}

Visualforce:

<apex:page standardController="contact" extensions="inlinecontroller">
<apex:form >
   <apex:pageBlock title="My Inline Visualforce page">
    Account Name <apex:outputField value="{!accRec.name}"/><br/>
     Account Number  <apex:outputField value="{!accRec.accountnumber}"/><br/>
     Annual Revenue  <apex:outputField value="{!accRec.annualrevenue}"/><br/>
   </apex:pageBlock>
</apex:form>
</apex:page>
Error:

Visualforce Error
Help for this Page

System.QueryException: List has no rows for assignment to SObject
Class.inlinecontroller.<init>: line 6, column 1