+ Start a Discussion
JuulJuul 

Go to Thank you page after pressing Update

Hi ,

 

What do I need to change to refer to a thank you page after pressing the button "Update"?

 

Class:

 

public class UpdateCampaignMemberClass{

    public final CampaignMember cm;

    private ApexPages.StandardController cmController;

    public UpdateCampaignMemberClass(ApexPages.StandardController controller) {
        cmController = controller;
        this.cm= (CampaignMember)controller.getRecord();
    }

    public PageReference UpdateAction() {
             try{
            update cm;
            }
            catch(DmlException ex){
            ApexPages.addMessages(ex);
            }
       
       return new PageReference('http://test.force.com/web2campaign/?id=' + cm.id );
    }   public string getStatus(string Status){
            return 'Test__c';
            return 'Test_2__c';
   } 
    
      
       
 }

VF:

 

<apex:page standardController="CampaignMember" extensions="UpdateCampaignMemberClass" sidebar="false" showHeader="false">

<script type="text/javascript"> 

function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
} } 

function showAlert(variable){
    alert(variable);
    }
</script>

<apex:form >
    <b>Campaign Member ID </b><apex:inputfield value="{!campaignmember.Id}"/><br/><br/>
            Status <apex:inputfield value="{!campaignmember.Test__c}"/><br/><br/>
            Status <apex:inputfield value="{!campaignmember.Test_2__c}"/><br/><br/>
    <apex:commandButton value="Update" action="{!UpdateAction}" />
    
    
    

</apex:form>
</apex:page>

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Avidev9Avidev9

THis is the line which takes you to the next page

 return new PageReference('http://test.force.com/web2campaign/?id=' + cm.id );

 

You have to update it to the new page some thing like "return Page.Thankyou"

 

All Answers

Avidev9Avidev9

Did you posted the correct code ? Seems like the code is messed up due to some formatting issues. Can you post ti again?.

 

 

But anyways if you want to redirect to a page. You have to make sure that your action method returns pagereference to that page.

public Pagereference update(){
     //your logic here
     /*Assuming there is a page with name "ThankYouPage" in your org*/
     return Page.ThankYouPage;
}

 

JuulJuul

Sorry something went wrong with the copy paste action :)

I've edited my previous post. Where do I need to add your code?

 

Thanks

Avidev9Avidev9

THis is the line which takes you to the next page

 return new PageReference('http://test.force.com/web2campaign/?id=' + cm.id );

 

You have to update it to the new page some thing like "return Page.Thankyou"

 

This was selected as the best answer
JuulJuul

Thanks, I thought that this line was necessary for a correct update!