0

We are using angular for front-end and Salesforce is being used for maintaining database. REST APIs have been written on Salesforce to communicate and fetch data to front-end. We have created Site/Community for Guest Users. These Guest Users have been assigned a Custom Profile with limited access. We have written a URL Rewritter class which after logging gets the Guest User to the desired URL. We have also written a VF page (HomePage) where the Guest User should be redirected after loggging in.

My requirement is that the Guest User (with Custom Profile) should be redirected to the VF Page (HomePage) however the other Profile users should redirect to a different Page (https://LoginToAU.force.com/AU/). How to achieve the same. Below is my URL Rewritter Class:

global class UrlRewriterClass implements Site.UrlRewriter {    

//Maps a user-friendly URL to a Salesforce URL

global PageReference mapRequestUrl(PageReference friendlyUrl) {
System.debug('UrlRewriterClass.mapRequestUrl: ' + friendlyUrl);

if(AppController.isPublicURL(friendlyUrl)) {
  return null;

} else {

  String url = friendlyUrl != null ? friendlyUrl.getUrl() : null;
  String regionID ='';
  String AU = 'AU_';
  Boolean GuestUser = TRUE;  
  String CUSTOMER_PROFILE_NAME = 'AU Guest User';
  Id profileId=userinfo.getProfileId();
  String profileName=[Select Id,Name from Profile where Id=:profileId].Name;

if (url.containsIgnoreCase('AU_Mb')){
    regionID = 'Mb';
    GuestUser = FALSE; 

}
else if (url.containsIgnoreCase('AU_Cb')){
    regionID = 'Cb';
    GuestUser = FALSE;            
}  

    if (GuestUser == FALSE) {

      String regionCode = '';
      String region = url.toLowerCase().substringAfter(AU.toLowerCase());

      if(region != null && region.length() > 0) {
          regionCode = '?sc=' + region;
      }

      return new PageReference('/apex/LoginTo_au_' + regionID + regionCode);

    } else {


    if (profileName == CUSTOMER_PROFILE_NAME) {
     return new PageReference('/apex/HomePage');
    } else {        

      return new PageReference('https://LoginToAU.force.com/AU/');        
    }

    }
  }
 }
}
  • It looks like you have already written the redirect code, so what is your question? If it is not working, you need to provide more details. – David Cheng Feb 23 '18 at 20:12
  • Yes, its not working. I'm getting redirected to the 'LoginToAU.force.com/AU' URL when logging with the Guest User Profile. My requirement is I should be redirected to /apex/HomePage when logging through Guest Profile only. All the other Profile users should be redirected to 'LoginToAU.force.com/AU' URL. – Salesforce Learner Feb 26 '18 at 6:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.