1

I am using pagereference introduced in summer'18(https://resources.docs.salesforce.com/214/latest/en-us/sfdc/pdf/salesforce_summer18_release_notes.pdf) and trying to navigate to the opportunity recordView page once the record created successfully. It is working fine when I am harcoding the Id but I am not sure how to pass the Id of newly created record in the JS controller.

Component.cmp

<aura:component>
 <aura:attribute name="url" type="String"/>
 <aura:handler name="init" value="{! this }" action="{! c.setPagref }"/>
 <lightning:navigation aura:id="navLink"/>  
 <aura:attribute name="recordId" type="string" />

 <lightning:button aura:id="submit" type="submit" label="Save Opportunity" class="slds-m-top_medium" onclick="{!c.navigate}"/>

Controller.JS

({
   setPagref : function(component, event, helper) {
    var navLink = component.find("navLink");

    var pageRef = {
        type: 'standard__objectPage',
        attributes: {
            actionName: 'list',
            objectApiName: 'Opportunity',

        },
        state: {
            filterName: "MyOpportunities"
        }
    };

    // Set the URL on the link or use the default if there's an error

    navLink.generateUrl(pageRef).then($A.getCallback(function(a) {
            component.set("v.url", a ? a : "#");
        }), $A.getCallback(function(error) {
            component.set("v.url", "#");
        }));
},
 navigate : function(component, event, helper) {
    var navLink = component.find("navLink");
    var payload = event.getParams().response;
    var recordId = component.get("v.recordId");
    alert('RecordId of Opp: '+recordId);
    var pageRef = {
        type: 'standard__recordPage',
        attributes: {
            actionName: 'view',
            objectApiName: 'Opportunity',
            recordId : '0064E000007QadyQAC'
        },
    };
    navLink.navigate(pageRef, true); })

Not sure but I am getting recordId value is "undefined" also I am not sure how to give the recordId in pagereference attribute. If I hardcode the opportunityId then its working fine. new record created and it's navigate to the opportunity which I hardcoded. Please help me to fetch the id of newly created record and how to mention it in the pagereference attribute.

1 Answer 1

1

The root cause is most likely because you have no implemented the force:hasRecordId interface in your component, thus your <aura:attribute name="recordId" type="string" /> attribute is not defined.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .