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
Anjum AttarAnjum Attar 

SObject row was retrieved via SOQL without querying the requested field: Opportunity.Name Error is in expression '{!SendEmail}' in component <apex:commandButton> in page oppinvoicemail: Class.EmailOppInvoice.SendEmail: line 27, column 1

//@author : Anjum Attar
//Creation Date :
//Modification History :
public with sharing class EmailOppInvoice {
    public Opportunity oppRecord{get;set;}
    public String id{get;set;}
    public String eSubject{get;set;}
    public String eBody{get;set;}
    //public  Contact objcon = new Contact();
    public EmailOppInvoice(ApexPages.StandardController controller) {
        oppRecord = (Opportunity)controller.getRecord();
        id =;
        oppRecord = [Select Id,Name,Email__c,Account.Id From Opportunity Where Id =: id];
        eSubject ='';
        eBody = '';
    public EmailOppInvoice() {
    public pageReference SendEmail() {
       Messaging.singleEmailMessage email = new Messaging.singleEmailMessage();
       PageReference pdfExample = new pagereference('/apex/OpportunityInvoice?id='+id);  
        Blob content = pdfExample.getContent();
        Messaging.emailFileAttachment fileAttachment = new Messaging.emailFileAttachment();
        String[] eAddress = new List<String>();
        try {
            email.setFileAttachments(new Messaging.EmailFileAttachment[] {fileAttachment});
            Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
            return null;
        catch(Exception e) {
             ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Email Field of Account does not contain any value'));
        return null;

Please share  your Visual force page. I am guessing the error is in commandbutton.

Kind regards,
Preya VaishnaviPreya Vaishnavi
Please use opprecord on the visualforce page to refer opportunity
Anjum AttarAnjum Attar
My VF Page :

<apex:page standardController="Opportunity" extensions="EmailOppInvoice">
<apex:form >
    <apex:pageBlock title="Send Opportunity Invoice to Account">
        <apex:pageMessages ></apex:pageMessages>
        <apex:outputLabel for="Subject" value="Subject"> : <br/></apex:outputLabel>
        <apex:inputText maxlength="80" id="Subject" size="80" value="{!eSubject}"/><br/><br/>
        <apex:outputLabel for="Body" value="Body">:<br/></apex:outputLabel>
        <apex:inputTextArea id="Body" rows="8" cols="80" value="{!eBody}"/><br/><br/>
        <apex:commandButton action="{!SendEmail}" value="Send"/>
Anjum AttarAnjum Attar
Please suggest me ...where I m doing wrong

the code you posted looks fine. Could you please post the code for  OpportunityInvoice vf page?