0

I would like to concatenate the "lang" parameter and I would also like to bring the "id" parameter behind whenever I switch the language.

Below is my current code:

//Language
   public PageReference switchLanguage(){

    if(this.language == 'en-US' ){
        this.language = 'it-IT';
    }else if(this.language == 'it-IT' ){
        this.language = 'en-US';
    }

    String campaignid = getCampaignId();

    String URL = '/apex/TrussardiEventForm?lang=' + this.language + '&campaignid' + campaignid;

    PageReference target = new PageReference(URL);

    target.getParameters().clear();
    target.getParameters().put('lang', this.language);    
    target.getParameters().put('Id', campaignid);

    return target.setRedirect(true); 
} 




//Read ID Campaign 
public String getCampaignId(){

    String campaignid;

    if( String.isNotBlank(ApexPages.currentPage().getParameters().get('Id')) ){
        campaignid = ApexPages.currentPage().getParameters().get('Id');
    }
    return campaignid;
}
  • 1
    You may want to elaborate your question- – Raul Oct 12 '17 at 14:27
  • I would like to concatenate the "lang" parameter and I would also like to bring the "id" parameter behind whenever I switch the language – Riccardo Cossu Oct 12 '17 at 14:29
  • Hi Riccardo, welcome to SFSE. Please take a moment to visit the help center, scroll through the tour, and read How to Ask. Please edit your post to include words which form a question. A good question will describe what you are trying to achieve at a high level, and where specifically your current implementation falls short. – Adrian Larson Oct 12 '17 at 14:33
  • the parameter "lang" remains chained in the url. I would also like to concatenate the parameter "id" that I step. – Riccardo Cossu Oct 12 '17 at 14:46
0

To redirect to a Visualforce page, you should use PageReference.existingPageName syntax, like this:

PageReference target = PageReference.MyVFPage;

Then you use the getParameters().put() method to set the parameters as you are doing, and it should work.

See documentation.

  • It is very difficult to read code that is in the comments section. Please edit your original post with your updated code and add some text in the post to describe the result you get. – David Cheng Oct 12 '17 at 18:59

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.