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

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'


insert SpR;

catch(DmlException ex)

PageReference thanksPage = new PageReference('');
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.


//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('', nextPage);