Snippets

jprichter Dynamic Navigation in Napili Communities

Created by jprichter
1
2
3
4
5
6
public class NapiliCommunityController {
    @AuraEnabled
    public static User getLoggedInUser(){
        return [SELECT Id, Contact.AccountId FROM User WHERE Id =: UserInfo.getUserId() LIMIT 1];
    }
}
1
2
3
<aura:component controller="NapiliCommunityController" implements="forceCommunity:availableForAllPageTypes" access="global">
	<aura:handler name="init" value="{!this}" action="{!c.redirectToAccount}" />
</aura:component>
({
    redirectToAccount: function(component, event, helper) {
        var loggedInUser;
        var state;
        var navEvt;
        
        var action = component.get("c.getLoggedInUser");
        action.setCallback(this, function(response) {
            state = response.getState();
            if (state === "SUCCESS") {
                loggedInUser = response.getReturnValue();
                navEvt = $A.get("e.force:navigateToSObject");
                navEvt.setParams({
                    "recordId": loggedInUser.Contact.AccountId,
                    "slideDevName": "detail"
                });
                navEvt.fire();
            }
        });
        $A.enqueueAction(action);
    }
})

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.