0

I have developed a lightning component as below.

I have a Lightning Component Navigate.cmp. In that a Button is there. When i click that button it should open a record of case there itself means in Salesforce1 app itself.(in my example i mentioned one satic ID)

But it's not opening the record. Can any one guide me how to open a record when button clicks.

Here is my Component and .js code

Component

<aura:component >
        <ui:button press="{!c.navigate}" label="NavigateURL" ></ui:button>
</aura:component>

.js

({
    navigate : function(component, event, helper) {
        var urlEvent = $A.get("e.force:navigateToURL");
        var myUrl = '#/sObject/' + '50028000002MXyV'+ '/view';
        urlEvent.setParams({
          "url": myUrl
        });
        urlEvent.fire();
        }
})

please guide me. I have stuck here. Thanks in advance.

1
  • This should work in Salesforce1. Are you testing the component in a standalone app outside of Salesforce1? Commented Sep 4, 2015 at 23:19

1 Answer 1

0

when navigating to a record using navigateToURL method, you can simply redirect to the record with relative base path like /{recordId}

so in your js method, if you use the below it should work..

({
    navigate : function(component, event, helper) {
        var urlEvent = $A.get("e.force:navigateToURL");
        var myUrl = '/50028000002MXyV';
        urlEvent.setParams({
          "url": myUrl
        });
        urlEvent.fire();
    }
})

you also need to add implements="force:appHostable" to your component to make it available in the S1 navigation.

<aura:component implements="force:appHostable">
        <ui:button press="{!c.navigate}" label="NavigateURL" ></ui:button>
</aura:component>
2
  • Thank u @Vamsi Superb......, It's working fine when the component added to Salesforce1 navigation directly and when that component added to app through lightning app builder, but when the same component added through Code . <aura:application> <MyNameSpace:Navigate/> </aura:application> It's getting error "Uncaught error in $A.run() : urlEvent is null"
    – Rock SFDC
    Commented Sep 5, 2015 at 19:14
  • if u r using the .app within a browser, the navigateToUrl won't work. you have to open the app in ur S1 mobile app for this to work. Commented Sep 6, 2015 at 10:27

You must log in to answer this question.

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