Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can anyone describe, what the colon and question mark syntax between the two methods is for?

public PageReference initialize() {
        String profileId = ApexPages.currentPage().getParameters().get('profileId');
        return profileId == null ? initializeView() : initializeUpdate();

Thanks a lot

share|improve this question
up vote 6 down vote accepted

This is just another syntax for creating an IF() statement. It is known as a ternary conditional operation. Take a look here for some more info on boolean and conditional statements.


return (profileId == null) ? initializeView() : initializeUpdate();

Says the same thing as THIS

if(profileId == null){
   return initializeView();
} else {
   return initializeUpdate();

Just helps save some code statements and makes the code a bit more readable.

share|improve this answer
Personaly, I like to put the condition into parenthesis for more readability like return (profileId == null) ? initializeView() : initializeUpdate(); – SF_user Aug 8 '14 at 14:16
Good point. That might help segment the parts a bit better to help improve readability. – Chris Duncombe Aug 8 '14 at 14:17
@sfdc_ninja sorry, I deleted my comment after you updated your question but before you replied to my comment – BarCotter Aug 8 '14 at 14:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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