0

I am going to create Wizard for custom object Vehicle__c. My fields are Vehicle_Number__c,Vehicle_Owner__c,Vehicle_Type__c(Pick list ) while saving in third page am getting an Error.

This is my Apex Code:

public class Vehicletest {
public Vehicle__c Fed{get;set;}

 public Vehicle__c getFed() {
      if(Fed== null) Fed = new Vehicle__c();
      return Fed;
   }
    public PageReference step1() {
      return Page.Newtest;
   }

   public PageReference step2() {
      return Page.Newtest2;
   }

   public PageReference step3() {
      return Page.Newtest3;
   }
 public PageReference cancel() {
            PageReference FeedbackPage = new ApexPages.StandardController(Fed).view();
            FeedbackPage.setRedirect(true);
            return FeedbackPage; 
    }
public PageReference save() {

PageReference FeedbackPage = new ApexPages.StandardController(Fed).view();
      FeedbackPage.setRedirect(true);

      return FeedbackPage;
   }

}

this is my Vf Code:

<apex:page controller="Vehicletest" tabStyle="Vehicle__c">
  <script>
  function confirmCancel() {
      var isCancel = confirm("Are you sure you wish to cancel?");
      if (isCancel) return true;

     return false;
  }  
  </script>
  <apex:sectionHeader title="New Customer Opportunity" subtitle="Step 1 of 3"/>
    <apex:form >
      <apex:pageBlock title="Customer Information" mode="edit">
      <apex:pageBlockButtons >
          <apex:commandButton action="{!step2}" value="Previous"/>
          <apex:commandButton action="{!save}" value="Save"/>
          <apex:commandButton action="{!cancel}" value="Cancel" 
                              onclick="return confirmCancel()" immediate="true"/>
        </apex:pageBlockButtons>
      <apex:pageBlockSection title="Account Information">

        <!-- Within a pageBlockSection, inputFields always display with their
             corresponding output label. -->
       <apex:inputField id="myPicklist" required="true" value="{!Fed.Vehicle_Type__c}"/><br /> <br /> 
              </apex:pageBlockSection>
       </apex:pageBlock>
  </apex:form>
</apex:page>

But am getting "Argument cannot be null" Error for save Button

1

@Novarg is right, that you've not define Fed correctly. That's why you're getting an error. Remove getFed() method since it can be done using get property in public Vehicle__c Fed{get;set;} itself. You should define Fed something like this:

public Vehicle__c Fed {
    get { 
        if(Fed== null) 
            Fed = new Vehicle__c();
        return Fed; 
    }
    set;
}

Refer documentation for get;set;

0
0

The problem is that your Fed is null when you click Save button.

You do not initialize it anywhere, except for getFed() method, which you do not call anywhere.

0

Remove

public Vehicle__c getFed() {
  if(Fed== null) Fed = new Vehicle__c();
  return Fed;
}

And add below code ( initialize the variable in the constructor )

public Vehicletest(ApexPages.StandardController controller) {
          Fed = new Vehicle__c();
}

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.