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
divya1234divya1234 

Redirect a page to custom object record page after alert message

I am trying to redirect  to the custom object record page after action in persfored by lightning button
Helper: function(component, event, getInputkeyWord) {
        // call the apex class method 
        var action = component.get("c.Function");// calling a method from aura enable class to persfor a opeation
        // set param to method  
        action.setParams({
            'Records': component.get("v.NextRecords")
        });
        // set a callBack    
        action.setCallback(this, function(response) {

            var state = response.getState();
            if (state === "SUCCESS") {
                var storeResponse = response.getReturnValue();
                // if storeResponse size is equal 0 ,display No Records Found... message on screen.                }
                if (storeResponse.length == 0) {
                    component.set("v.Message", 'No Records Found...');
                } else {
                    component.set("v.Message", '');
                    // set searchResult list with return value from server.
                }
                component.set("v.UserList", storeResponse);
                alert('operation perfored  Sucessfully'); // showing a message once operation is completed
				/// trying to redirect the page from lightning component page to record detai page
               var navEvent = $A.get("e.force:navigateToSObject");
              navEvent.setParams({
              recordId: component.get("v.objSobject").Id,
              slideDevName: "detail"
         });
         navEvent.fire();

I am getting This page has an error. You might just need to refresh it. Error in $A.getCallback() [Cannot read property 'setParams' of undefined] Callback failed: apex://ETre/AuarApexClass/ACTION$UserFunction Failing descriptor: {markup://c:MultiSelectLookup}
Sachin HoodaSachin Hooda
Hi Divya,
Well, the mentioned  "e.force:navigateToSObject" & "sforce.one.navigateToSObject" still doesn't work in some cases. So you can try an alternative approach to redirect the user to the created page. 
The alternative approach is to use lightning:navigation, (https://developer.salesforce.com/docs/component-library/bundle/lightning:navigation/documentation" target="_blank) salesforce document itself suggests to use this.
<lightning:navigation aura:id="navigateme"/>
Give it a try & if any issue occurs, please post it here.


Regards,
Sachin Hooda
(:
David Zhu 🔥David Zhu 🔥
You may missed the double quotation mark when setting the parameters. Please try the code below.
 
var navEvent = $A.get("e.force:navigateToSObject");
              navEvent.setParams({
              "recordId": component.get("v.objSobject").Id,
              "slideDevName": "detail"
         });
         navEvent.fire();
divya1234divya1234
This page has an error. You might just need to refresh it. Error in $A.getCallback() [Cannot read property 'setParams' of undefined] Callback failed: apex://reUsableMultiSelectLookupCtrl/ACTION$UserFunction Failing descriptor: {markup://reUsableMultiSelectLookup}
after
<aura:attribute name="url" type="String"/>
    <aura:attribute name="pageReference" type="Object"/>
    <aura:handler name="init" value="{! this }" action="{! c.init }"/>
    <lightning:navigation aura:id="navService"/>
    <a href="{!v.url}">Link</a>


  ({
    init : function(cmp, event, helper) {
        var navService = cmp.find("navService");
        // Sets the route to /lightning/o/Account/home
        var pageReference = {
            type: 'standard__objectPage',
            attributes: {
                objectApiName: 'Account',
                actionName: 'home'
            }
        };
        cmp.set("v.pageReference", pageReference);
        // Set the URL on the link or use the default if there's an error
        var defaultUrl = "#";
        navService.generateUrl(pageReference)
            .then($A.getCallback(function(url) {
                cmp.set("v.url", url ? url : defaultUrl);
            }), $A.getCallback(function(error) {
                cmp.set("v.url", defaultUrl);
            }));
    }
})

 
Sachin HoodaSachin Hooda
Hi Divya,
I doubt if navigation is causing any error. Can you please update your complete code, So we can assist you better.
_______
Regards,
Sachin
(: