You need to sign in to do that
Don't have an account?
Problem showing detail page for a newly created contact
I am using VisualForce pages and Apex to convert a spouse to a contact. A new button was added to the Contacts detail pages to call the VF page. All is going fairly well, but I cannot get the detail page of the new contact to show.
Part of my custom controller code is shown below and is based on the 'The Opportunity Wizard Controller' section in the VF developers guide to show the detail page of the newly created contact.
//Save the new contact public PageReference NContact(){ Contact newcontact = new contact (LastName = SLNAME); insert newcontact; PageReference contactPage = new ApexPages.StandardController(contact).view(); contactPage.setRedirect(true); return contactPage;
I get the following error message:
System.NullPointerException: Argument 1 cannot be null
The bold line above is referenced.
Hey
Just a small thing really
return contactPage;
I've never used the standard controller in this manner though. If you're still having issues I *think* this will work
PageReference contactpage = new PageReference(newcontact.id);
Cheers,
Wes
All Answers
Hey
Just a small thing really
return contactPage;
I've never used the standard controller in this manner though. If you're still having issues I *think* this will work
PageReference contactpage = new PageReference(newcontact.id);
Cheers,
Wes
Thanks, Wes. That worked. It sure is hard for me to find this stuff out from the documentation.
Two solutions worked for me. Any comments on which might be preferred:
PageReference contactPage = new ApexPages.StandardController(newcontact).view();
PageReference contactPage = new PageReference('/' + newcontact.id);
Mark
I've never done it the first way before but to me it seems the best way.. simply because it's cleaner than my way.
There are cases in which the second method would be better e.g. you want to direct the user to a visualforce page that you've made, and need to specify parameters dynamically.
Thanks for teaching me something:)
Wes