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

getUrl(); returning weird post data - how to cleanse?
Hi all,
I'm using getUrl to help redirect users after they post (upsert) data through a controller. However, when the page refreshes, the URL string contains all sorts of weird data (acutally, the post data itself). Any ideas about how to cleanse this out, and only return the URL string, e.g.,
https://c.cs2.visual.force.com/apex/CTN_Lessons_12
instead of
https://c.cs2.visual.force.com/apex/CTN_Lessons_12?apprenticeshipId=a0GR000000190tPMAQ&com.salesforce.visualforce.ViewStateCSRF=.81nmB5NLIKSowfGW68Ozh1YbfyQRA_PK9vLzSMZ3B_DbvoIIPncNlNIIPA6744H7JTmluAAQsrSYvwoegMBZ.aPpHdlcZMSZmDIIi2y05XT7rqH4KEw6M2yM8vez7ChXCXnKw8lY0REsEIBobzuEt2hXVY%3D&ctContactId=003R000000Ea03n&id=a0eR0000000IqirIAC&j_id0%3Aj_id13=j_id0%3Aj_id13&j_id0%3Aj_id13%3AActivity_1__c=asdads&j_id0%3Aj_id13%3AActivity_1_Time__c=&j_id0%3Aj_id13%3AActivity_2__c=asdads&j_id0%3Aj_id13%3AActivity_2_Time__c=&j_id0%3Aj_id13%3AActivity_3__c=&j_id0%3Aj_id13%3AActivity_3_Time__c=&j_id0%3Aj_id13%3AAgenda=tst&j_id0%3Aj_id13%3ACollege_Career=asdasd&j_id0%3Aj_id13%3ACT_Introduction__c=&j_id0%3Aj_id13%3ACT_Introduction_Time__c=&j_id0%3Aj_id13%3ADebrief_Questions__c=&j_id0%3Aj_id13%3ADebrief_Questions_Time__c=&j_id0%3Aj_id13%3Aj_id15=j_id0%3Aj_id13%3Aj_id15&j_id0%3Aj_id13%3AMaterials=asdasd&j_id0%3Aj_id13%3AObjectives=test&j_id0%3Aj_id13%3ARitual=&j_id0%3Aj_id13%3ARitual_Time__c=&j_id0%3Aj_id13%3AWOW_em__c=&j_id0%3Aj_id13%3AWOW_em_Time__c=?apprenticeshipId=a0GR000000190tPMAQ
...?
Here's my code:
public PageReference save() { PageReference pageRef = System.currentPageReference(); url = pageRef.getUrl(); try{ if (pageRef.getParameters().get('lessonNumber') != null) { lessonplan.Lesson_Number__c = pageRef.getParameters().get('lessonNumber'); } lessonplan.Name = 'Web Submission'; lessonplan.Apprenticeship__c = pageRef.getParameters().get('apprenticeshipId'); lessonplan.Last_CT_Modified__c = pageRef.getParameters().get('ctContactId'); upsert(lessonplan); }catch(Exception e){ String myErr = '?err=' + e.getMessage(); PageReference ref = new PageReference('/apex/testerr' + myErr); ref.setRedirect(true); return ref; } // url = '/apex/CTN_Lessons_12'; lessonid = lessonplan.id; apprenticeshipId = pageRef.getParameters().get('apprenticeshipId'); ctContactId = pageRef.getParameters().get('ctContactId'); urlstring = url + '?apprenticeshipId=' + apprenticeshipId + '&ctContactId=' + ctContactId + '&id=' + lessonid; // urlstring = url + '?id=' + apprenticeshipId + '&ctContactId=' + ctContactId; PageReference ref = new PageReference(urlstring); ref.setRedirect(true); return ref; }
Thanks for your help!
Split your url string, and use string functions to clean it up...
PageReference currPage = ApexPages.currentPage(); String currPageURL = currPage.getUrl(); // Used to figure out current page a bit better: if (currPageURL.contains('?')) { List<String> currPageSplit = currPageURL.split('\\?'); if (currPageSplit[0] != null) currPageURL = currPageSplit[0]; } System.debug('************************************'); System.debug('** currPage = ' + currPage); System.debug('** currPageURL = ' + currPageURL); System.debug('************************************');
All Answers
Split your url string, and use string functions to clean it up...
PageReference currPage = ApexPages.currentPage(); String currPageURL = currPage.getUrl(); // Used to figure out current page a bit better: if (currPageURL.contains('?')) { List<String> currPageSplit = currPageURL.split('\\?'); if (currPageSplit[0] != null) currPageURL = currPageSplit[0]; } System.debug('************************************'); System.debug('** currPage = ' + currPage); System.debug('** currPageURL = ' + currPageURL); System.debug('************************************');
Hi Dave,
Could you please format you code properly and paste it again to help us debug it correctly?
- A J
Hey there --
I'm pasting in through Eclipse and IE (it's formatted properly on my end) but jumbling on-post... I'll try a different browser combination later on today.
--Dave