How to create a Community Lightning Component


How to create a Community Lightning Component

Building Custom Lightning Components for salesforce Communities

Step:-1 Create Apex Class HelloWorld.apxc

public class HelloWorld {
    public static string getUserName()
        return userinfo.getName();

Step:-2 Create Lightning Component with name UserInfoComponent.cmp

<aura:component controller="HelloWorld" implements="forceCommunity:availableForAllPageTypes" access="global" >
	<aura:attribute name="userName" type="string"></aura:attribute>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <p>Hello <b>{!v.userName}</b>,How Are You</p>

Step:-3 Create Component Controller for doInit Action

    doInit : function(component, event, helper) {

Step:-4 Create Component helper for doInit

    getUserRecord : function(component) {
        var action=component.get("c.getUserName");
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (component.isValid() && state === "SUCCESS") {
                var userName = response.getReturnValue();

Step:5 Open Community builder drag the particular component from the custom component

Step:6 Publish the site

After Publish it look like

you can visit below link how to create community site

About the author

nayakdillip administrator

Leave a Reply