0

I have a lightning community where I am trying to update user record when the user clicks the specific button but what happens is when I call that controller from header it updates the records and the community loads up but when I call my controller from inner component It does not update record and community does not loads up at all

Here is the Component

<aura:component implements="forceCommunity:availableForAllPageTypes,force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId" access="global" controller="POC_TrainingController">
<ltng:require scripts="/resource/jquery"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<div>
    <div class="slds-container_large slds-container_center">
        <div class="block">
            <div class="slds-grid slds-wrap">

                <lmsilt:Training />                  
            </div>
        </div>
    </div>
</div>
</aura:component>

Here is Controller

({
reactivateUser : function(component, event, helper) {
     var action = cmp.get("c.reactivateUser");
action.setCallback(this, function(response){
    var state = response.getState();
        if (state === "SUCCESS") 
        {
            console.log('SUCCESS');
        }
    else if(state === "ERROR")
    {
         console.log('ERROR');
    }
    else {
            console.log('There was a problem : '+response.getError());
        }

})
 $A.enqueueAction(action);
},


showVideo1 : function(cmp, event) {
    $("#video1").show();
},
closeModal : function(cmp, event) {
    $(".video-modal").each(function( index ) {
        $( this ).hide();
    });
}
})

Here is my apex class

public with sharing class POC_TrainingController {

@AuraEnabled
public static void reactivateUser()
{
List<GroupMember> gm = [SELECT ID from GroupMember WHERE Group.Name='PC Training DASH Upgrade' AND UserOrGroupId=:UserInfo.getUserId()];
if(UserInfo.getUserId()!=Null && gm.size()>0)
    {
    List<User> currentUser = [select Id,lmscons__Cornerstone_ID__c,CFS_Activation_Date__c,lmscons__CFS_Status__c from User where Id =: UserInfo.getUserId()];
    if(currentUser.size()>0 && currentUser[0].lmscons__Cornerstone_ID__c!=NULL && currentUser[0].lmscons__CFS_Status__c=='Deactivated')
        { 
            currentUser[0].lmscons__CFS_Status__c='Active';    
            currentUser[0].CFS_Activation_Date__c =  datetime.now();
        }
    update currentUser[0];
    }
}
}
2
  • When you say, ` but when I call my controller from inner component` is it <lmsilt:Training /> ? If so, please can you paste the code for that component and it's controller? I hope that component also has the apex controller listed.
    – markgarg
    Commented May 26, 2018 at 16:32
  • <lmsilt: Training/> is a component of the managed package.
    – Ishan
    Commented May 29, 2018 at 10:23

1 Answer 1

0

You are missing the call-back function. Have a look at the documentation.

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/controllers_server_actions_call.htm

Essentially you need to do something like,

doInit : function(cmp, event) {
    var action = cmp.get("c.reactivateUser");

    action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                //do your logic
            }
            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);
},
7
  • I added the call back still no luck
    – Ishan
    Commented May 23, 2018 at 9:26
  • Check the debug logs to confirm whether your apex method is firing. Also check you have controller="POC_TrainingController" defined on the component markup and also check your console logs whether there are any errors.
    – Ranga
    Commented May 23, 2018 at 9:47
  • No, my method is not firing and I am including the controller="POC_TrainingController" markup
    – Ishan
    Commented May 23, 2018 at 10:08
  • hmm interesting! can you provide your code for the full component and js controller?
    – Ranga
    Commented May 23, 2018 at 10:15
  • Also it would help if you provide your main component as well as sub component. Is your button in the top level component?
    – Ranga
    Commented May 23, 2018 at 10:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .