I'm working with a standard controller on one of our organizations objects and have identified the parameter Id of a field we'd like to populate when a new record is being created.

in the controller class I put that value into a string variable

string parentLookup = 'CF0..._lkid';


string lookupId = ApexPage.currentPage().getParameters().get(parentLookup);

returns null...

when I output the pageParameters map I can see that string is in the keySet() but if I loop through the keys and compare them using charAt() and codePointAt() I get different values for each character in the two strings.

I know that means the encoding is different or something, but am unsure of the best way to fix that issue. Any suggestions?

Below are the additional pieces of information requested:

URL result


Controller Constructor

Public WRTaskController(ApexPages.StandardController controller){
    String parentParameterId = 'CF00N0t000000qOYu_lkid'; 
    String parentNameParameterId = 'CF00N0t000000qOYu'; 
    for(string each : ApexPages.currentPage().getParameters().keySet()){
        if(!each.contains('lkid')) continue;
        for(integer x = 0; x < parentParameterId.length(); x++){

Debug output:

|USER_DEBUG|[43]|DEBUG|{ CF00N0t000000qOYu=IT-2031, CF00N0t000000qOYu_lkid=a310t000000MY1Y, retURL=a310t000000MY1Y, RecordType=0120Z000001AmEUQA0, save_new=1, sfdc.override=1}
|USER_DEBUG|[45]|DEBUG| CF00N0t000000qOYu
|USER_DEBUG|[45]|DEBUG| CF00N0t000000qOYu_lkid
|USER_DEBUG|[49]|DEBUG|67 (charAt output)
|USER_DEBUG|[50]|DEBUG|32 (charAt output)
|USER_DEBUG|[51]|DEBUG|67 (codePointAt output)
|USER_DEBUG|[52]|DEBUG|32 (codePointAt output)

  • 2
    Those parameters are ASCII. You shouldn't have different character sets involved. Can you include a complete example of your debug output and the code that tries and fails to get it? My first culprit to look for is a case difference; Map gets are case sensitive in Apex, unlike everything else. – David Reed Nov 21 '18 at 22:03
  • offhand, what you're doing looks right, can you post an example URL from when you're page loads, a snippet of the visualforce page showing the apex:page tag, and a snippet of your extension with the constructor. that may help us spot the hangup – Ralph Callaway Nov 21 '18 at 23:19
  • Consider a query in your extension constructor, and reference your field by API name. Have you considered taking this approach? Is there a reason you led with a solution that relies on the field ID, rather than a query and reference to field API name? – krigi Nov 21 '18 at 23:33
  • I'll add some more detailed snippets here soon, but to answer @krigi the reason we're using the field Id parameters is that this is an overload for a new record, so I have nothing to query if I can't pass something into the page and retrieve it. – Jerry Daru Nov 23 '18 at 13:49

These are ASCII strings. There is no need to go to the code point level or the character level to compare them. Let's look at what your debugs actually show, though, because the solution is hidden in there.

I'm going to pull out every other pair, because we don't need code points.

|USER_DEBUG|[49]|DEBUG|67 (charAt output)
|USER_DEBUG|[50]|DEBUG|32 (charAt output)

Since you alternate, between strings, this is the first three characters of each. If we consult an ASCII chart, we find that they are

67.70.48 == 'CF0'
32.67.70 == ' CF'

One of your strings has a spurious space character at the head. It appears this is each, the incoming parameter, which would suggest your URL hack that is pointing to this page is configured incorrectly and has a typo in the URL.

  • You rock thanks, the button that invoked this redirect was a URL button. I didn't look at it because the pageparameter map looked right.... there were spaces... – Jerry Daru Nov 23 '18 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.