0

I have to Displaying Custom Banner Component on case record page when Case Owner is not equal to login user. For that i created lightning component. But problem is every time I have to reload the page to show Banner message when case owner is not equal to login user and when case owner is equal to log in user its displaying only empty banner without any message.

ErrorMsg.cmp

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" controller="CaseOwnerController" >
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
     <aura:attribute name="recordId" type="String" />
    <aura:attribute name="ErrorMsg" type="String"/>
    <aura:attribute name="isboolean" type="Boolean" default="true"/>
    <aura:if isTrue="{!v.isboolean}">
      <div class="slds-card" style="padding:10px;">
        <div role="alert" 
          style="background-color:#fff;color:red;border-radius:0.25rem;font-size: 14px;">
            {!v.ErrorMsg}
        </div>
        </div>      
    </aura:if>
</aura:component>

ErrorMsgContriller.js

({
    doInit : function(component, event, helper) {
        var action=component.get("c.getCaseDetails");
        var caseid=component.get("v.recordId");
        console.log("Case id is:"+caseid);
        action.setParams({
            "caseid":caseid
                        });
        action.setCallback(this,function(response)
        {
             var state=response.getState();
            if(state=="SUCCESS")
            {
                 var storeResponse = response.getReturnValue();   
                 component.set("v.ErrorMsg",storeResponse);
            }
        });
        $A.enqueueAction(action);
    },

})

CaseOwnerController.apxc

public class CaseOwnerController {

     @AuraEnabled
     public static String getCaseDetails( Id caseid) 
     {
        list<Case> lstC = [select Id,Owner.Username from Case where id=:caseid];
            for (Case obj: lstC) 
            {
                 if(obj.OwnerId!=userinfo.getuserId())
                    { 
                    return 'Only the case owners are authorised to send email on a case.';
                    }
            }
        return '';
}
}
1

Have you tried using the Visibility Filter on the component in the App Builder? You'd have to add a boolean formula field on the Case to indicate whether the current User ID is equal to the Owner ID, then base your Visibility Filter on that formula field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.