+ Start a Discussion
Patrick Sluck 5Patrick Sluck 5 

Variable does not exist: standardController

On line 10 of my Class, I get the error listed in the subject line above.  Unsure how to resolve.  I am working on adding the attachments option to my VF Page listed below as well.  Please help!!

public class VFAttachments {
        public Id recordId;

    public VFAttachments() {
        
    }


    public VFAttachments(ApexPages.StandardController controller) {
        this.recordId = (Trip_Report__c)standardController.getRecord().Id;
    }


public Attachment attachment {
  get {
      if (attachment == null)
        attachment = new Attachment();
      return attachment;
    }
  set;
  }

  public PageReference upload() {

    attachment.OwnerId = UserInfo.getUserId();
    attachment.ParentId = recordId; // the record the file is attached to
 //   attachment.ParentId = ApexPages.currentPage().getParameters().get('id'); 
    attachment.IsPrivate = true;

    try {
      insert attachment;
    } catch (DMLException e) {
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
      return null;
    } finally {
      attachment = new Attachment(); 
    }

    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Attachment uploaded successfully'));
    return null;
  }
}


VF Page Below....

<apex:page standardController="Trip_Report__c" >
    <style>
      .activeTab {background-color: #2ECCFA; color:white; 
         background-image:none}
      .inactiveTab { background-color: lightgrey; color:black; 
         background-image:none}
   </style>
    <script>
        function confirmSave() {
            var isSave = confirm("Your Trip Report has been saved!");
            if (isSave) return true;
  
        return false;
        }
    </script>
    <apex:form >
        <apex:pageBlock title="Trip Report">
            <apex:pageBlockButtons >
                <apex:commandButton value="Save As Draft" action="{!save}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
                <apex:commandButton value="Delete" action="{!delete}"/>
            </apex:pageBlockButtons>
        <apex:pageBlockSection columns="1">      
            <apex:inputfield required="true" value="{!Trip_Report__c.Name}" label="Visit"/>
            <font style="margin-left:240px" size="0.25" color="blue"> <b> Enter: 'TR'-Company Name-Subject for the Visit</b></font>
            <apex:inputfield required="true" value="{!Trip_Report__c.Purpose_of_Visit__c}" label="Purpose Of Visit"/>
            <apex:inputfield value="{!Trip_Report__c.Visit_Date__c}" label="Date"/>
            <apex:inputfield value="{!Trip_Report__c.Lead_Source__c}" label="Lead Source"/>
            <apex:inputfield value="{!Trip_Report__c.Opportunity__c}" label="Opportunity"/>
            <apex:inputfield value="{!Trip_Report__c.Campaign__c}" label="Campaign"/>
        </apex:pageBlockSection>
        <apex:pageBlock title="Attendees">
            <apex:pageBlockSection columns="2">
                <apex:inputfield value="{!Trip_Report__c.Attendees__c}" label="Client Attendees"/>
                <apex:inputfield value="{!Trip_Report__c.PL_Attendees__c}" label="Internal Attendees"/>
            </apex:pageBlockSection>
        </apex:pageBlock>    
        <div>
            <apex:pageBlock title="Trip Details & Notes">
            <apex:tabPanel switchType="client" selectedTab="sch" tabclass="activeTab" inactivetabclass="inactiveTab">
                <apex:tab label="Objectives">
                    <apex:inputfield value="{!Trip_Report__c.Objectives__c}" label="Objectives/Reason For Visit" style="width: 1250px; height: 100px"/>
                </apex:tab>
                <apex:tab label="Background">
                    <apex:inputfield value="{!Trip_Report__c.Background__c}" label="Background Information" style="width: 1250px; height: 100px"/>
                </apex:tab>
                <apex:tab label="Discussions">
                    <apex:inputfield value="{!Trip_Report__c.Discussion__c}" label="Discussions" style="width: 1250px; height: 100px"/>
                </apex:tab>
                <apex:tab label="Trip Summary">
                    <apex:inputfield value="{!Trip_Report__c.Summary__c}" label="Trip Summary" style="width: 1250px; height: 100px"/>
                </apex:tab>
                <apex:tab label="Actions/Questions">
                    <apex:inputfield value="{!Trip_Report__c.Actions_Questions__c}" label="Actions/Questions" style="width: 1250px; height: 100px"/>
                </apex:tab>
            </apex:tabPanel>
            </apex:pageBlock>
        </div>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Best Answer chosen by Patrick Sluck 5
vijayabhaskarareddyvijayabhaskarareddy
Hi patrick,

Pls  replace with line 10 with below code , your problem will be solved
 
recordId = [select id from Trip_Report__c where id = :ApexPages.currentPage().getParameters().get('id')].id;
Regards
vijay
 

All Answers

Hemant_SoniHemant_Soni
Hi Patrick Sluck 5,
This error occured because you use wrong validable  in this line "this.recordId = (Trip_Report__c)standardController.getRecord().Id ",
you need to use this line in your code "this.recordId = (Trip_Report__c)controller.getRecord().Id".
I think this may help you.Please mark it best if it helps you.
thanks
Hemant
Rahul Chaudhary 21Rahul Chaudhary 21
Hemant is right above. Use controller rather than standardController variable.
vijayabhaskarareddyvijayabhaskarareddy
Hi patrick,

Pls  replace with line 10 with below code , your problem will be solved
 
recordId = [select id from Trip_Report__c where id = :ApexPages.currentPage().getParameters().get('id')].id;
Regards
vijay
 
This was selected as the best answer