+ Start a Discussion
LloydCLloydC 

Button to create a new contact

Hi,

I am creating a wizard to create a case with some particular requirements.  After selecting the account, the user selects an existing contact on the account.  If the contact doesn't exist the user should be allowed to create a new contact for that account.  Does anyone know how to: with a button click, send the user to the new contact page with the selected account, return to the calling page and update the contacts in a select list?

 

 

I do have a controller extension for the wizard but don't know how to go about calling a standard page, new contact, and returning.  Mostly I have tried to use the UrlFor function but can't get all the functionality implemented.

 

Thanks for any help.

 

Lloyd

 

Best Answer chosen by Admin (Salesforce Developers) 
NaishadhNaishadh

It is because of default SalesForce save button functionality. You have to replace it with custom save button.

All Answers

NaishadhNaishadh
PageReference pg = new PageReference('/003/e'); 
ApexPages.currentPage().getParameters().put('retURL',<your current page url>);
ApexPages.currentPage().getParameters().put('cancelURL',<your current page url>);
ApexPages.currentPage().getParameters().put('override','1');
pg.setRedirect(true);
return pg;

 

 

LloydCLloydC

Thanks,

I tried putting this in the controller extension but apparently I am doing something else wrong which must be the same thing I did in the command button:

 

action="{!urlFor($Action.contact.newcontact,null,[retUrl=$Request.returl],true)}"

The address when it goes to the contact new page becomes:

https://na6.salesforce.com/003/e?retURL=https%3A%2F%2Fc.na6.visual.force.com%2Fapex%2Fcasestep2&nooverride=1

 

When I save the contact, it goes to the contact view and not the retURL above.

 

Any ideas?

 

NaishadhNaishadh

It is because of default SalesForce save button functionality. You have to replace it with custom save button.

This was selected as the best answer
LloydCLloydC

Thanks, that makes some sense.

Being relatively new to Salesforce, I don't know how to create a custom save button that implements both of the functions, i.e., custom and default; so, I created a custom "add new" contact page and added it to the wizard.  It does look like the custom save goes the return url when it is from another standard page and I would think that it would go to the return url that is passed in the Action.

 

 

Thanks again.