2

Salesforce has functions that do a lot of basic web app functionality for you, called Event Reference. They can be found here https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_events.htm

On the editRecord Event Reference, found here https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_force_editRecord.htm

essentaily, I create a

<ui:button label="Edit" press="{!c.editRecord}"/>

on my component, reference the attribute on the page and add the function from the docs in the controller

editRecord : function(component, event, helper) {
    var editRecordEvent = $A.get("e.force:editRecord");

    console.log("record id is: " + component.get("v.item.Id"));
    console.log("editRecordEvent value is: " + editRecordEvent);

    editRecordEvent.setParams({
        "recordId": component.get("v.item.Id")
    });

    editRecordEvent.fire();
}

correct?

Here is the odd thing. From the console.logs, I get the record id, but the editRecordEvent returns undefined. What is going on? Is there something I need to reference in my component to use Event Reference?

enter image description here

  • 1
    Look at this answer this will help.This solution applies to all e.force:XXX events – Praveen Jul 15 '16 at 19:15
  • @Praveen I'm iterating over a component. Do I put the handler outside the iteration or put it in the iterated component? – Tyler Zika Jul 15 '16 at 19:34
  • 1
    If you get the id in the iterated (child) component,pass the id to the parent component through component event.So obvious place to put the handler is on the parent component. – Praveen Jul 15 '16 at 19:53
  • Can't get it to work :( – Tyler Zika Jul 15 '16 at 20:09
  • This seems too messy for an out-of-the-box event. – Tyler Zika Jul 15 '16 at 20:24
0

You don't state details of how you are using this component, but here is a possible explanation.

There are a number of features in Lightning components that exist only in certain web containers...in other words certain lightning apps.

The force:editRecord event is one of these.

Essentially when you invoke a component in the context of the URL [hostname]/one/one.app (the URL for Salesforce1 mobile and for Lightning Experience), there are a bunch of resources that are martialled up and put in place a developer can make use of without any extra work.

From the docs:

This event is handled by the one.app container. It’s supported in Lightning Experience and Salesforce1 only. If used outside of Lightning Experience or Salesforce1, this event won’t be handled automatically. To use this event outside of one.app, create and wire up an event handler of your own.

However, if use a different application context (either because I want to create my own Lightning app, or because I am doing some initial testing with a Lightning Component perhaps), those events are not supported, and thus not available to retrieve from the Aura context at runtime.

A complete list of these components is in this answer related to another question Lightning for Visualforce.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.