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

code not working for sites page - save record and go to new url
public class saveAndThanks
{
String Account = ApexPages.currentPage().getParameters().get('Unknown Account CSR');
Sponsorship_Request__c SR;
private ApexPages.StandardController controller;
public saveAndThanks(ApexPages.StandardController controller)
{
this.controller = controller;
}
public PageReference saveAndThanks()
{
Sponsorship_Request__c SpR = new Sponsorship_Request__c
(
//OwnerId = '00GE0000000hCBH',
RecordTypeId = '01250000000DvDq',
Account__c = '0015000000ch107'
);
try
{
insert SpR;
}
catch(DmlException ex)
{
ApexPages.addMessages(ex);
}
PageReference thanksPage = new PageReference('http://www.sample.com/index.html');
thanksPage.setRedirect(true);
return thanksPage;
}
static testMethod void testsaveAndThanks() {
//Use the PageReference Apex class to instantiate a page
PageReference pageRef = Page.SampleSponsorship;
//In this case, the Visualforce page named 'SampleSponsorship' is the starting point of this test method.
Test.setCurrentPage(pageRef);
//set the field values of job details
//values entered in VF page can be set here
Sponsorship_Request__c SR = new Sponsorship_Request__c(
Account__c = '0015000000ch107',
Organization__c = 'Test Job',
Contact_Name__c = 'test name',
Options__c = 'test project name');
//Instantiate and construct the controller class.
ApexPages.StandardController thecontroller = new ApexPages.StandardController(SR);
saveAndThanks controller = new saveAndThanks(thecontroller);
//The .getURL will return the page url the Save() method returns.
String nextPage = controller.saveAndThanks().getUrl();
//Check that the save() method returns the proper URL.
System.assertEquals('http://www.sample.com/index.html', nextPage);
}
}