function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
johnhurleyjohnhurley 

"Contact Us" form submission

Hey there!

 

Newbie needs some help with a client Salesforce site.  I have a "Contact Us" form with the standard form fields (name, email, phone, etc.),  when in developer mode, the form submits , saves and redirects to the new record in the "Message" custom object.  But seeing as this is a public site, I don't want them going to the new record page.  If I fill the form as anonymous user, I get the "Authorization Required" page, which is supposed to happen as they have no permissions to that section in the app.  It also doesn't save the record.

 

What I am trying to do is have the form filled out as anonymous user, save the new record, and forward the user to a "thank you" page.  Is there any way of easily doing this?  Or do I need to work with triggers and whatnot?

 

Thanks in advance!

John

Best Answer chosen by Admin (Salesforce Developers) 
jkucerajkucera

Sounds like you want a conditional redirect upon submit - is that right?  You can do this by calling a method in a controller extension that returns a pagereference which is the URL you want them to go to.

 

<apex:form id="theForm" onsubmit="myMethod()" >
public PageReference myMethod() {
try{
update myObject;
}
catch(DmlException ex){
ApexPages.addMessages(ex);
}
return new PageReference('http://www.DesiredReturnURL.com/');
}

 

All Answers

jkucerajkucera

Sounds like you want a conditional redirect upon submit - is that right?  You can do this by calling a method in a controller extension that returns a pagereference which is the URL you want them to go to.

 

<apex:form id="theForm" onsubmit="myMethod()" >
public PageReference myMethod() {
try{
update myObject;
}
catch(DmlException ex){
ApexPages.addMessages(ex);
}
return new PageReference('http://www.DesiredReturnURL.com/');
}

 

This was selected as the best answer
johnhurleyjohnhurley

Thanks for the reply John!  That is pretty much what I was asking, however, I just found out from my boss that the client just wants the information to go through a web-to-lead form (gotta love the communication around here :P), which made things MUCH easier.  So help me, I WILL learn Salesforce (wish I could afford the training classes LOL).

 

Have a great day!