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
Rocio VivancoRocio Vivanco 

Would like to avoid hardcoding of IDs within a URL, using custom labels, without success

Hi all,

I have a code where I am using URLs and don't want to hardcode IDs in my APEX Code, so I was looking for syntax how to declare a URL with custom labels.

For example, this is the code which works in APEX:
 
public PageReference GotoPreinscripcionList() {

      shouldRedirect = true;
      url = '/a05?fcf=00B3E000000TsVm';
      //url.setredirect(true);
      return null;
     
     }
And this is the last attempt to make it work with custom labels (my 100th try):
 
public PageReference GotoPreinscripcionList() {

       shouldRedirect = true;
       String preinscripcion_FR_Id = Label.Preinscripcion_FR_ID;
       String preinscripcion_listview_Id = 
       Label.Preinscripcion_Postgrado_ListView;
       url = 'preinscripcion_FR_Id?fcf=preinscripcion_listview_Id';
       //url.setredirect(true);
       return null;
    }
Nothing happens. Even with 
 
String preinscripcion_listview_Id = 
       '{!$Label.Preinscripcion_Postgrado_ListView}';
Does anybody know how to handle this?


 
Best Answer chosen by Rocio Vivanco
Raj VakatiRaj Vakati
Hi , 
Try some think like this 
public PageReference GotoPreinscripcionList() {

 String preinscripcion_FR_Id = Label.Preinscripcion_FR_ID;
       String preinscripcion_listview_Id = Label.Preinscripcion_Postgrado_ListView;
       String urlTemp = preinscripcion_FR_Id'?fcf='+preinscripcion_listview_Id;
PageReference pr =new PageReference(urlTemp) ; 

       pr.setredirect(true);
       return null;
	   
        }

 

All Answers

Raj VakatiRaj Vakati
Hi , 
Try some think like this 
public PageReference GotoPreinscripcionList() {

 String preinscripcion_FR_Id = Label.Preinscripcion_FR_ID;
       String preinscripcion_listview_Id = Label.Preinscripcion_Postgrado_ListView;
       String urlTemp = preinscripcion_FR_Id'?fcf='+preinscripcion_listview_Id;
PageReference pr =new PageReference(urlTemp) ; 

       pr.setredirect(true);
       return null;
	   
        }

 
This was selected as the best answer
Rocio VivancoRocio Vivanco
Thank you very much, Rajamohan!!!. It worked this time :). I really appreciate it.