function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Brian11Brian11 

Server side Controller not working when using the following implement lightning:recordHomeTemplate

Any functions on the client side controller work without a problem but If i have to make a call to an apex server The function doesnt exists.
Is this a behavior that is not allowed?
 
public with sharing class ContactRecordHomeController {
    
    @AuraEnabled
    public static String updateStatus() {
         User user = [Select sidebar_Status__c From User Where Id = :UserInfo.getUserId()];
         user.sidebar_Status__c = !user.sidebar_Status__c;
         update user;
        return 'user';
    }

}

 
Khan AnasKhan Anas (Salesforce Developers) 
Hi Brian,

I trust you are doing very well.

According to the information provided by you, it seems that you are using the same JavaScript method name as the Apex controller method. According to this post (https://salesforce.stackexchange.com/questions/129261/enqueued-action-not-executed-in-lightning-component), "A javascript method name in a component controller can never be the same name in an apex lightning controller".
Just need to change the name of your javascript method to be different from the apex method.

If the problem still persists, please share your complete code.


I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in future.

Thanks and Regards,
Khan Anas
Brian11Brian11
Hey Khan,

I should have shared the entire code. but the client side controller names are different. I cant find any documentation on (lightning:recordHomeTemplate) limplents. I'm not sure if thats just not allowed when using the implements

Component: 
 
<aura:component controller="ContactRecordHomeController" implements="lightning:recordHomeTemplate" description="A home page for the contact record page"
    access="global">
    <aura:attribute name="header" type="Aura.Component[]" description="Header region" />
    <aura:attribute name="main" type="Aura.Component[]" description="Main region" />
    <aura:attribute name="sidebar" type="Aura.Component[]" description="Collapsible sidebar region" />

    <aura:attribute name="isSidebarCollapsed" type="Boolean" access="PRIVATE" default="false" />

    <div>
        <div>{!v.header}</div>
        <lightning:layout class="slds-m-top_medium">
            <lightning:layoutItem flexibility="auto">
                {!v.main}
            </lightning:layoutItem>
            <lightning:layoutItem flexibility="no-flex">
                <lightning:button variant="base" label="Base" title="Base action" onclick="{!c.toggleSection}" class="bg-gray h-100 w-30">

                    <lightning:buttonIcon class="design-allow-interaction toggle slds-p-around_xxx-small slds-m-horizontal_xx-small absolute top-left"
                        variant="bare" iconName="{! v.isSidebarCollapsed ? 'utility:back' : 'utility:forward' }" alternativeText="{! v.isSidebarCollapsed ? 'Expand Sidebar' : 'Collapse Sidebar' }">
                    </lightning:buttonIcon>
                    <span class="rotate-text">{! v.isSidebarCollapsed ? 'Open Sidebar' : 'Hide Sidebar' }</span>

                </lightning:button>
            </lightning:layoutItem>
            <lightning:layoutItem class="{! v.isSidebarCollapsed ? ' slds-hide' : '' }" size="4">
                {!v.sidebar}
            </lightning:layoutItem>
        </lightning:layout>
    </div>
</aura:component>
Client Side Controller:
({
    toggleSection: function (component, event, helper) {
        let saveSidebarStatus = component.get("c.saveSidebarStatus");
        saveSidebarStatus.setCallback(this, function (response) {
            let user = response.getReturnValue();
            console.log("user",user)
        })
        $A.enqueueAction(saveSidebarStatus);
    }
})

Apex Controller:
public with sharing class ContactRecordHomeController {
    
    @AuraEnabled
    public static String saveSidebarStatus() {
        User user = [Select sidebar_Status__c From User Where Id = :UserInfo.getUserId()];
        user.sidebar_Status__c = !user.sidebar_Status__c; 
        update user;
        return 'user';
    }

}

Kunal Ghosh 17Kunal Ghosh 17
Hi Brian11,

did you find any solution for this?

Thanks in advance
Tiwari VedantTiwari Vedant
Same issue for me. Is it resolved? Please comment