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
Ragnar Lothbrok 7Ragnar Lothbrok 7 

Can we make the event work based on Profile?

Hi there,
Is there a way that we can target the event of a field (Standard field - Case Owner) and make it run based on some profile and show pop-up confirmation message and once its confirmed change owner else dont change the owner.
How can we do this?
Thank you.
PriyaPriya (Salesforce Developers) 
Hey Ragnar,

For this you need to make custom page i.e., Aura Component.

I am going to explain you sample scenario with the below example:-

The Lightning Overlaylibrary and Application Component will help you to achieve this:

I have design a sample component for you which will helps you:

1. Create one Application Event :(Name as OverlayLibraryModalEvent)
 
<aura:event type="APPLICATION" description="Event to handle overlay Action" >
 <aura:attribute name="message" type="String"/>
</aura:event>



2. Create the Overlay Component :(Name as OverlayLibraryModal) ==> This will hold the OK and Cancel button

Here am passing the string as which button getting clicked to parent component via Application event
 
<aura:component access="global">
    <aura:registerEvent name="appEvent" type="c:OverlayLibraryModalEvent"/>
    <lightning:overlayLibrary aura:id="overlayLib"/>
    
    <!--Component Start--> 
    <div class="slds-text-align_center slds-m-around_x-medium">
        <lightning:button name="cancel" label="Cancel" onclick="{!c.handleCancel}"/>
        <lightning:button name="ok" label="OK" variant="brand" onclick="{!c.handleOK}"/>
    </div>
    <!--Component End-->
</aura:component>



OverlayLibraryModal JS:
 
({
    handleCancel : function(component, event, helper) {
        //closes the modal or popover from the component
        var appEvent = $A.get("e.c:OverlayLibraryModalEvent");
        appEvent.setParams({
            "message" : "Cancel" });
        appEvent.fire();
        component.find("overlayLib").notifyClose();
    },
    handleOK : function(component, event, helper) {
        //do something
        var appEvent = $A.get("e.c:OverlayLibraryModalEvent");
        appEvent.setParams({
            "message" : "Ok" });
        appEvent.fire();
        component.find("overlayLib").notifyClose();
    }
})



3. Parent Comonent :  (Component which hold the initial submit button)

Once you have recievd the which button clicked msg then do the further operation handleApplicationEvent method
 
<aura:component  implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome" access="global">
    <!--Declare Attribute-->
    <aura:attribute name="FirstName" type="String"/> 
    <aura:attribute name="LastName" type="String"/> 
    
    <aura:handler event="c:OverlayLibraryModalEvent" action="{!c.handleApplicationEvent}"/>
    
    <lightning:overlayLibrary aura:id="overlayLib"/>
    
    <!--Component Start-->   
    <div class="slds-m-around--xx-large">
        <lightning:input name="fname" label="First Name" value="{!v.FirstName}" />
        <lightning:input name="lname" label="Last Name" value="{!v.LastName}" />
        <br/>
        <lightning:button variant="brand" label="Show Modal" onclick="{!c.handleShowModal}"/>
    </div>
    <!--Component End-->
</aura:component>



Parent Comonent JS:
 
({
    handleShowModal: function(component) {
        var fName = component.get("v.FirstName");
        var lName = component.get("v.LastName");
        $A.createComponent("c:OverlayLibraryModal", {},
                           function(content, status) {
                               if (status === "SUCCESS") {
                                   var modalBody = content;
                                   component.find('overlayLib').showCustomModal({
                                       header: "Hi " + fName +" "+ lName + " Please let us know your confirmation!!!",
                                       body: modalBody, 
                                       showCloseButton: false,
                                       closeCallback: function(ovl) {
                                           console.log('Overlay is closing');
                                       }
                                   }).then(function(overlay){
                                       console.log("Overlay is made");
                                   });
                               }
                           });
    },
    
    handleApplicationEvent : function(cmp, event) {
        var message = event.getParam("message");
        alert('@@@ ==> ' + message);
        if(message == 'Ok')
        {
        // if the user clicked the OK button do your further Action here
        }
       else if(message == 'Cancel')
      {
        // if the user clicked the Cancel button do your further Action here for canceling
      }
    }
})




https://developer.salesforce.com/docs/component-library/bundle/lightning:overlayLibrary/documentation

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!

Thanks & Regards,

Priya Ranjan