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

SaveURL question

Good day, 


When i trying to pass in more than one parameter to saveURL, and it does go to right page but do not show more than one paramater in the saveURL. the code sample like below, after the contact save, it should go to 'another' page with parameter show for 'accountName=' and 'modified=true' , but it seem like only appear accountName and newId , but 'modified=true' no longer showing.



PageReference newContactView = new PageReference('/apex/myContact?accountId='+accountId+'&saveURL=/apex/anotherpage?accountName='+accountName + '&modified=true');


Thank you !



You have to URL Encode all the stuff in the SaveURL, otherwise the browser thinks that all the params specified in it are actually just a part of the original URL.



global static String encodeURL(String variable){
        	return (EncodingUtil.urlEncode(variable,'UTF-8'));
        else {
        	return '';


Thanks werewolf !



above is my encode method , and below is how to encode it , but it seem no luck



PageReference newContactView = new PageReference('/apex/mycontact?accountId=' + accountId +  PageUtils.encodeURL('&saveURL=/apex/anotherpage?accountName='+accountName + '&created=yes' ));


it give me invalid id error , i have try debug by capture 'accountId', which is actually passing the whole string like


accountid= xxxABCDEF&saveURL=/apex/anotherpage?accountName=Abc corp&created=yes and not xxxABCDEF


any clue on this ?





To help you debug it, you could save the URL you're generating into a separate string and System.debug that. 


However I can see what your problem is: you're close, but now you're URLEncoding too much.  You don't want to URL encode the part that says &saveURL=, just the actual URL that follows it.