+ Start a Discussion
noor Zabinoor Zabi 

Create a lightning component which has three button --Button 2 - to display the success toast message (Which contains record id)

Components:--

<aura:component controller="Staffbutton" implements="lightning:availableForFlowActions, force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
       
    <aura:attribute name="Staffbutton" type="string"/>
    <aura:attribute name="StaffdId" type="String"/>  
<lightning:button label="Success" variant="brand"
         onclick="{!c.displaymsg}"/>
    </div>
</aura:component>

Controller:-
displaymsg: function (component, event, helper) {
         var toastEvent = $A.get("e.force:showToast");
            //fire the toast event in Salesforce app and Lightning Experience
            toastEvent.setParams({
                "title": "Success!",
                "type": "success",
                "mode": 'dismissable',
                "message": "The component successfully load."+component.get('v.recordId')
            });
            toastEvent.fire();
    
    
            }})



I'm not unable display record Id with toast message.

I'm getting this one..User-added image
Best Answer chosen by noor Zabi
Surya GSurya G
Hi Noor Zabi, 
for the above requirement, no need for a controller class, just place the component on any object record page, it will work. try this below code.
let me know if iany questions
<aura:component implements="lightning:availableForFlowActions, force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
       
    <lightning:button label="Google" variant="brand"
         onclick="{!c.openGoogleUrl}"/>
         <lightning:button label="Refresh" variant="brand"
         onclick="{!c.refreshPage}"/>
    <lightning:button label="Success" variant="brand"
         onclick="{!c.displaymsg}"/>
    
</aura:component>


controller:


({ 
    openGoogleUrl : function(component, event, helper) { 
        window.open("https://www.google.com/",'_blank') 
    },
    refreshPage : function(component, event, helper) { 
        location.reload(); 
    }, 
    displaymsg: function (component, event, helper) { 
      
        var toastEvent = $A.get("e.force:showToast"); 
        //fire the toast event in Salesforce app and Lightning Experience 
        toastEvent.setParams({ 
            "title": "Success!",
            "type": "success",
            "mode": 'dismissable', 
            "message" : "The component successfully load "+component.get('v.recordId') 
        }); 
            toastEvent.fire(); 
        }
    })
Thanks
Surya G
 

All Answers

Suraj Tripathi 47Suraj Tripathi 47
Hi Noor Zabi,
Greeting!

your controller is working properly. If this is your full code then your controller is not getting any record id and the RecordId attribute you are using is also not initialized inside your aura component and you are not passing value inside your RecordId attribute that's why your code is not working and showing Javascript error.
If you have more in this code post it.
Otherwise, create the RecordId attribute and pass the value in it, and then it will work without any error.

If you find your solution then mark this as the best answer.

Thank you!
Regards,
Suraj Tripathi
Surya GSurya G
Hi Noor Zabi,
Your code is working fine, I have tried in my dev org where I can see the toast message with record ID. I think the problem is related to the controller, try to post your full code, we can check where it is going wrong. As of now, I see no issues with the success button and action handler.

Thanks
Surya G
noor Zabinoor Zabi
Components:-
Controller: - ({ //Open Google Url googleUrl : function(component, event, helper) { window.open("https://www.google.com/",'_blank') }, //Refresh Page refreshpage : function(component, event, helper) { location.reload(); }, displaymsg: function (component, event, helper) { var action = components.get("c.getrecord") action.SetParams({ 'stf':components.get("v.Staffbutton") }); action.setCallback(this, function(data) { component.set('v.staffId',data.getReturnValue()) }); var toastEvent = $A.get("e.force:showToast"); //fire the toast event in Salesforce app and Lightning Experience toastEvent.setParams({ "title": "Success!", "type": "success", "mode": 'dismissable', "message" : "The component successfully load "+component.get('v.Staffbutton') }); toastEvent.fire(); }}) Class: - public class Staffbutton { @AuraEnabled public static List getrecord(){ List Stf =[Select Id FROM Staff__c]; return Stf; } } This complete code tell me where i went wrong.
Surya GSurya G
Hi Noor Zabi, 
what functionality do you need on click of the success button?  do you want to show the record ID of staff__c object with toast message?
And what is staff button attribute? where you are passing value to that?
can you please brief me on the requirement, so we can suggest a solution accordingly.

Thanks
Surya G
noor Zabinoor Zabi
Yes. When I click success button. It should display last save record id with toast message.
noor Zabinoor Zabi
This is questions..? 1. Create a lightning component which has three button 2. 1. Button 1 - to refresh the page onclick 2. Button 2 - to display the success toast message (Which contains record id) 3. Button 3 - Navigate to www.google.com (use navigate to URL ) I got a and c, bit b is I'm not able to do.
Surya GSurya G
Hi Noor Zabi, 
for the above requirement, no need for a controller class, just place the component on any object record page, it will work. try this below code.
let me know if iany questions
<aura:component implements="lightning:availableForFlowActions, force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
       
    <lightning:button label="Google" variant="brand"
         onclick="{!c.openGoogleUrl}"/>
         <lightning:button label="Refresh" variant="brand"
         onclick="{!c.refreshPage}"/>
    <lightning:button label="Success" variant="brand"
         onclick="{!c.displaymsg}"/>
    
</aura:component>


controller:


({ 
    openGoogleUrl : function(component, event, helper) { 
        window.open("https://www.google.com/",'_blank') 
    },
    refreshPage : function(component, event, helper) { 
        location.reload(); 
    }, 
    displaymsg: function (component, event, helper) { 
      
        var toastEvent = $A.get("e.force:showToast"); 
        //fire the toast event in Salesforce app and Lightning Experience 
        toastEvent.setParams({ 
            "title": "Success!",
            "type": "success",
            "mode": 'dismissable', 
            "message" : "The component successfully load "+component.get('v.recordId') 
        }); 
            toastEvent.fire(); 
        }
    })
Thanks
Surya G
 
This was selected as the best answer
noor Zabinoor Zabi
[image: Screenshot (180).png] Everything is going well, but record id is not display. Can please explain me. Actually i'm still in training only
Surya GSurya G
Hi Noor Zabi, you have to place this aura component in record page to show the record ID.
noor Zabinoor Zabi
Thank you for your reply. \