2

We need to enable community users to be able to edit their contact fields through My Profile. But it's showing only User details. To cater that I tried building a lightning component to read user Id and respective contact Id and then populate a component using . I'm now trying to get Lightning Contact Record Detail (standard record page component) into my custom lightning component. Below is my code. Any help would be appreciated. Thanks.

My markup:

<aura:component controller="MyProfileController" implements="flexipage:availableForAllPageTypes,forceCommunity:availableForAllPageTypes,force:appHostable" access="GLOBAL">

        <aura:attribute name="contactID" type="String" description="" />
        <aura:handler name="init" value="{!this}" action="{!c.myAction}" />

        <aura:attribute name="simpleRecord" type="Object"/>

        <force:recordData aura:id="forceRecordCmp" 
                   recordId="{!v.contactID}"
                   layoutType="FULL" 
                   mode="VIEW"
                   targetRecord="{!v.simpleRecord}"
         />

        Test User Profile cmp info.
</aura:component>

Controller:

({
    myAction : function(component, event, helper) {
        helper.getMyProfileInfo(component);
    }
})

Helper:

({
    getMyProfileInfo : function(component) {

        var act = component.get("c.getUserContactId");

        act.setCallback(this, function(response){
                var ret = response.getReturnValue();

                console.log(ret);
                component.set("v.contactId", ret);

                component.find("forceRecordCmp").reloadRecord();
            });

            $A.enqueueAction(act);
    }
})

Apex class method:

@AuraEnabled
public static String getUserContactId(){
    id userId = UserInfo.getUserId();
    User u = [select id, contactId, FullPhotoUrl from User where id = : userId];
    String contactId = u.contactId;
    system.debug('User contact Id: ' + contactId);

    return contactId;
}
  • Please tell us the problem - if your code does not work, what happens? do you have errors?.... – Itai Shmida Sep 7 '17 at 6:35

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.