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

Return PageReference from a webservice method

I have a custom button that executes javascript.


sforce.apex.execute("TestClass","CreateTestRecords", {id:"{!Case.Id}"});


In my apex class I want to return a PageReference to the same page from where the custom button was clicked (refreshing the page).  Is that possible using a webservice static method?


global class TestClass {
	WebService static void CreateTestRecords(String caseId) {
		List<Fulfillment__c> fulfillmentsToCreate = [select Id from Fulfillment__c where Case__c =: caseId];
		if(!fulfillmentsToCreate.isEmpty() && fulfillmentsToCreate.size() > 0) {
			insert fulfillmentsToCreate;



I was trying to avoid using a VF page and just handle everything in a controller.  Is that possible?




I have a very similar issue with webservice.


maybe we can use JS to refernce the user to the right page...?


In your Class use a String as a Returntype


and create your reference like this in your webservice class



return String.valueOf( new PageReference('/'+Case.Id).getUrl());


and in your Button, you have to catch your return String and reload the page:


var newurl = sforce.apex.execute("TestClass","CreateTestRecords", {id:"{!Case.Id}"});
parent.location.href = newurl; //refresh the page