3

I am trying to add some extra validation to a form by checking if the fields are not null. I would like to loop through

ApexPages.CurrentPage().getParameters()

That looks something like this:

{
  "type": "Cookies",
  "personalNumber": "15000",
  "j_id0:temp:applicationForm:Years_Employed": "",
  "j_id0:temp:applicationForm:Work_Title": "",
  "j_id0:temp:applicationForm:Work_Phone_Number": "",   
  "j_id0:temp:applicationForm:Value_of_Other_Assets": "",
  "com.salesforce.visualforce.ViewStateVersion": "201702211931250209",
  "AJAXREQUEST": "_viewRoot"
}

I was trying to do something like this

    List<String> tester = new List<String>();
    tester.add('Years_Employed');
    tester.add('Work_Phone_Number');
    tester.add('Value_of_Other_Assets');
    for(String s:tester){
        s = 'j_id0:temp:applicationForm:'+s;
        if(ApexPages.CurrentPage().getParameters().get(s) == null){
            //CODE
        }else{
            //CODE
        }
    }

And this seems to do the trick, but I am affraid that if for some reason I need to change/add/wrap a field in an apex like an output panel, then this validation will fail

for(XXXXX param: ApexPages.CurrentPage().getParameters()){

}
7

try like this.. ApexPages.CurrentPage().getParameters() return a map . you have to use like below code.

for(String param: ApexPages.CurrentPage().getParameters().keyset())
{
    System.debug('===key==='+param);
    System.debug('===value==='+ApexPages.CurrentPage().getParameters().get(param));
}
| improve this answer | |
3

ApexPages.CurrentPage().getParameters() returns a Map.

So you can do like:

Map<String, String> urlParamentersMap = ApexPages.CurrentPage().getParameters();
for(String key : urlParamentersMap.keySet()){
    System.debug('key>>> '+key);
    System.debug('value>>> '+urlParamentersMap.get(key));
    //your logic
}
| improve this answer | |

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.