function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Cesar Ramirez Vasquez005391619375684564Cesar Ramirez Vasquez005391619375684564 

How can i swap a hidden variable in the web form depending on where is the page coming from ?

For example i got a field called origin if it is coming from facebook i want to save FB and if it come from the web save the value WEB, how can i do that im pretty new ?

Thanks
Best Answer chosen by Cesar Ramirez Vasquez005391619375684564
VictorFelisbinoVictorFelisbino
in your extension or controller constructor you can get the page referer

String ref = System.currentPageReference().getHeaders().get('Referer');

After getting that you can check it against a pattern to make sure its facebook or any other web...
Example:
String ref = System.currentPageReference().getHeaders().get('Referer');
if(ref == null) ref = '';
system.debug('**************Referer: ' + ref);
//In this pattern i want to get the two grouping in between the / , so i use the ( ) to separate each grouping
Pattern p = Pattern.compile('^.*\\.com/([a-z]{2})/([a-z]{2})/.*$');
Matcher m = p.matcher(ref);
 if(m.Matches()) {
     //FB
}else{
    //WEB
}

All Answers

VictorFelisbinoVictorFelisbino
in your extension or controller constructor you can get the page referer

String ref = System.currentPageReference().getHeaders().get('Referer');

After getting that you can check it against a pattern to make sure its facebook or any other web...
Example:
String ref = System.currentPageReference().getHeaders().get('Referer');
if(ref == null) ref = '';
system.debug('**************Referer: ' + ref);
//In this pattern i want to get the two grouping in between the / , so i use the ( ) to separate each grouping
Pattern p = Pattern.compile('^.*\\.com/([a-z]{2})/([a-z]{2})/.*$');
Matcher m = p.matcher(ref);
 if(m.Matches()) {
     //FB
}else{
    //WEB
}
This was selected as the best answer
Cesar Ramirez Vasquez005391619375684564Cesar Ramirez Vasquez005391619375684564
Thanks really usefull !