This button code overrides the new
button on a custom object. It sends the user to the record type selector, and then passes in a couple of params. When the user gets to the new record edit page, and THEN clicks cancel, he goes back to https://cs16.salesforce.com/home/home.jsp
not the accountId page as I want. Can someone help me with the syntax?
Schema.DescribeSObjectResult dsr = customObject__c.SObjectType.getDescribe();
Account a = [select id, name from Account where id = :this.AcctId];
url = '/setup/ui/recordtypeselect.jsp?';
url += 'ent=' + '01I30000001ITcu&';
url += 'retURL=/' + a.id ;
url += '&nooverride=1';
url += '&save_new_url=/' + dsr.getKeyPrefix() + '/e?';
url += 'CF00N3000000689TM=' + EncodingUtil.urlEncode(a.name, 'UTF-8') ;
url += '&CF00N3000000689TM_lkid=' + a.id;
url += '&retURL=/'+ a.id;
Best Answer
The issue here is that the
save_new_url
value needs to be encoded so that those parameters don't replace the parameters with the same names in therecordtypeselect.jsp
URL. Note that I used the encoded%2F
in place of the/
in thesaveNewUrl
string.I typically use a
PageReference
to do this as it automatically handles the URL Encoding and is a lot less fragile and error-prone than building a string by hand.Example debug output, with the second
retURL
value now double-encoded: