Skip to main content

How to show Current User Profile Picture in Lightning Component

Hello frnds today post learn how to show current user profile picture in lightning component
so let us start.......

Step=>1.
           goto developer console and create lightning component
             File=>New=>Lighning Component
               DisplayUserPhoto.cmp

<aura:component controller="LoginUserProfileCtrl"
                implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction"
                access="global" >
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute name="oUser" type="user" default="{'sobjectType' : 'User'}" />
    <h1>Current User Profile Picture</h1>
    <div style="padding:100px">
        <img src="{!v.oUser.FullPhotoUrl}" alt="{!v.oUser.Name}"/>
           <br/><br/>
        <img src="{!v.oUser.SmallPhotoUrl}"  alt="{!v.oUser.Name}"/>
           <br/><br/>
        <lightning:avatar src="{!v.oUser.SmallPhotoUrl}" />
    </div>
 
</aura:component>

Step=>2.
     DisplayUserPhotoController.js

   ({
    doInit : function(component, event, helper) {
        var action = component.get("c.fetchUserDetail");
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                var res = response.getReturnValue();
                component.set('v.oUser', res);
            }
            else if (state === "INCOMPLETE") {
                // do something
            }
                else if (state === "ERROR") {
                    var errors = response.getError();
                    if (errors) {
                        if (errors[0] && errors[0].message) {
                            console.log("Error message: " +
                                        errors[0].message);
                        }
                    } else {
                        console.log("Unknown error");
                    }
                }
        });
        $A.enqueueAction(action);
    },
})

Step=>3.
    create a Apex Class
            goto File=>New=>Apex Class

       LoginUserProfileCtrl.apxc

  public class LoginUserProfileCtrl {
  @AuraEnabled
    public static user fetchUserDetail(){
        return [Select id,Name,SmallPhotoUrl, FullPhotoUrl
                From User
                Where Id =: Userinfo.getUserId()];
    }
}

                                   

                            Output:


Thanks.!

Buy me a coffeeBuy me a coffee

Comments

  1. Могу практически напомнить, что onetwoslim капли для похудения one-two-slim-kapli.ru Стали просто моей настоящей страховкой в противостоянии с лишними кг - с их помощью я похудела на 14 килограммов за 2 месяца. До того, как я узнал об этом замечательном средстве, которое я не пробовал в то же время! В настоящее время проводятся всевозможные диеты, кодирующие от лишнего веса - однако эти методы не давали оптимального эффекта и всегда были связаны с этим эмоциональными нагрузками, стрессом от различных ограничений. И масса тела всегда возвращалась, на первом этапе отбора, к прежнему уровню, а после этого становилась еще больше. Так же, как я узнал о комплексе onetwoslim, я рекомендую его всем сегодня.

    ReplyDelete

Post a Comment

Popular posts from this blog

How to used slds-hide/show class for div hide and show in lightning component

Hello friends today post ,how to create a lightning component to use slds-hide/show class, very easy to use class and aplly.. so let us start ... firstly create a lightning component and there are two or three div or anything when you want to hide/show ... so see given bellow example and udes slds-hide/show class Step=>1.                   goto developer console=>File=>New=>Lightning Component                           sldshideshow.cmp <aura:component >     <aura:attribute name="First" type="string" default="slds-show"/>     <aura:attribute name="Second" type="string" default="slds-hide"/>         <center>     <div class="slds-box" style="width:300px;height:300px;margin-top:15px;">         <div class="{!v.First}">         ...

Create Overlays with the New Modal Component

Hello friends, Now modal tag is available in #LWC, we can create a modal using the #LWC Standard tag. snapshot given below with code. Step-1 Create LWC component Step-2 Add below code Step-3 I am showing how my component is look like. Thanks for reading

How to create Dynamic Generic Tree grid using LWC

Hello frnds todat i am talking about , how to create tree-grid using lwc Step-1:- First create Custom metadata, Click setup and In Quich Search box type " Custom metadata " Step-2:- Click on Custom metadata and click on "New custom metadata type" type custom metadata name and save after that create custom feilds, list given below image after that click on "manage" enter field api name according to your requirement Example given below Step-3:- Create Apex class Name is "SLMT_GenericHierarchiesController" global class SLMT_GenericHierarchiesController { @AuraEnabled(cacheable=true) global static List getFullHierarchies(Id recordId,String parentRelationship){ Id topLevelParentId = SLMT_GenericHierarchiesController.getUltimateParent(recordId,parentRelationship); List treeColumns = SLMT_GenericHierarchiesController.describeHierarchyMappings(recordId); List additionalFields =new List (); ...