• Rahul Chaudhary 21
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
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>