+ Start a Discussion
Amit Kumar Singh 19Amit Kumar Singh 19 

Switch one community to another community based on single user login

We have multiple communities in our org.Say for example. c1,c2...cn
User is trying to login via community "c1" portal and wants to navigate to "c2" community portal.
Is this possible to switch the community portal using single login?
global CommunitiesLoginController(){
        returnURL = ApexPages.currentPage().getParameters().get('returnURL');
        
        if(returnURL <> null){
            startURL = '/'+returnURL.substring((returnURL.lastIndexOf('/')+1));
            
        }
        System.debug('RETURN URL>>>>>>>.'+returnURL);
        sYSTEM.debug('startURL>>>>>>>>>'+startURL);
        
    }
    
    global PageReference login() {
        System.debug('Username>>>>>>>>>>'+login_Username);
        System.debug('Password>>>>>>>>>>'+login_Password);
        //Check Whether is already existing or Not
        if(returnURL <> null){
            PageReference authorized = Site.login(login_Username,login_Password,startURL);
            system.debug('authorized>>>>>>>>>');
            if(authorized <> null){
                List<User> userList = [Select Id,ContactId FROM User Where Username=:login_Username];
                System.debug('Result user>>>>>>.'+USERLIST.SIZE()+'Contact Id>>>>>>>'+userList[0].ContactId+'User Id>>>>>>'+userlist[0].id);
                if(userList.size() > 0){
                    List<Navigator_Contact__c> nc = [Select Account_Info__r.Order_Access__c FROM Navigator_Contact__c Where Parent_Contact__c=:UserList[0].ContactId];
                    sYSTEM.DEBUG('nAVIGATOR RESULT>>>>>'+nc);
                    if(nc.size() > 0){
                        if(nc[0].Account_Info__r.Order_Access__c == true){
                            system.debug('I am User but I have Order Navigator Access'+returnURL);
                            return authorized;
                            
                        }
                    }
                }
                
            }
alvaro olivenciaalvaro olivencia
Did you find a solution to this ?