You need to sign in to do that
Don't have an account?

VF Extension - PageReference Save() - Not saving page
I have two VF pages in a wizard. The idea is when the user hits Save on the first page, it grabs a field I have titled OppID__c from the Account and redirects the user to the second VF page ("/apex/closeopp2?id=" + OppID). The redirect works great, but the extension doesn't actually save any of the fields entered on the first page of the wizard. Code below:
public class CloseOppRedirect{ private final Account a; public CloseOppRedirect(ApexPages.StandardController controller){ this.a = (Account)controller.getRecord(); } //hoping that this will get me the OppID public PageReference save() { Account a = [select ID, OppID__c from Account where ID =:ApexPages.currentPage().getParameters().get('id')]; String Oppid = a.OppID__c; PageReference contPage = new PageReference('/apex/closeopp2?id=' + Oppid); contPage.setRedirect(true); return contPage; } }
I am super new to APEX so any help would be greatly appreciated.
Could I see the code for the visual force page. That might help.
Surely, attached:
You don't seem to be actually doing the save. You extension class save method needs to call the standard controller save method to get the save done.
I actually did notice that I was missing the save method. However, upon adding it I was still having issues. When I access my VF page and save the record, I get the below error:
System.NullPointerException: Attempt to de-reference a null object
Class.CloseOppRedirect.save: line 15, column 9 External entry point
Line 15, Col 9 points to the save method. I am unsure what it means to de-referene a null object when that object is the save method. Updated code below.
You need to set the controller field of the class so it is available in the save method. i.e. in the constructor, set
this.controller = controller;
to save the object that is passed to the constructor for later use.
Thank you, aballard!!! Not having much experience, it is great to come to these boards and utilize the great salesforce minds out there!!!!
Final code below (let's hope this is final :smileyhappy: ):