2

I am looking for a way to open a note linked to a record in enhanced note editor on a button click (see attached). Has anyone come across a similar requirement? Is there a way to achieve this? enter image description here

1 Answer 1

3

okay, after some snooping, I think I figured out something.

just a WARNING, this is undocumented and so utilizing this doesn't guarantee that this will continue to work.

I found that there's an undocumented event called "notes:editNote" which expects 4 parameters (at least based on the code, it used getParam() to get these four keywords: noteId, reEnableEditNote, contextList and openInObjectHome). Based on my testing, the noteId is obvious to be the Note's record id. The purpose and behavior of reEnableEditNote (a boolean), contextList and openInObjectHome are still unknown.

Here's my helper.js function that invokes it:

editNote : function(noteId) {
    var editEvent = $A.get("e.notes:editNote");
    editEvent.setParams({
        "noteId": noteId
    });
    editEvent.fire();
}

Everything below can be ignored, but, if you want to know how I figured this out, read on.

The Snooping

Using Google Chrome's devtool, in 'Sources' tab, you would see the list of files the whole page utilizes. Under "top/_your_site_url_/components/notes" folder, you would see a file called "editPanelManager.js". That's the file where this event is defined.

Note: The file is minified. Beautify it first to get a better look :)

Excerpts from the file:

        }, {
            "ed": {
                "descriptor": "markup://notes:editNote"
            },
            "x": {
                "exprType": "PROPERTY",
                "byValue": false,
                "path": "c.editNote"
            }

From the "helper" block, where you would see the function itself (note: there's another one in the controller block that calls this one)

                editNote: function(b, c) {
                    var a = this,
                        e = c.getParam("noteId");
                    if (c.getParam("reEnableEditNote")) b.set("v.editNoteEnabled", !0);
                    else {
                        var d = c.getParam("openInObjectHome");
                        !$A.util.isUndefinedOrNull(e) && 0 === e.length && (e = null);
                        if ($A.get("$Browser.isDesktop") && d) $A.getEvt("markup://force:selectSObject").setParams({
                            recordId: e
                        }).fire();
                        else {
                            var h = {
                                    eventDef: e ? "noteRowClick" : "newNote",
                                    recordId: e
                                },
                                g =
                                c.getParam("contextList");
                            $A.get("$Browser.isDesktop") && ($A.util.isUndefinedOrNull(e) && $A.util.isUndefinedOrNull(g)) && (g = [{
                                id: $A.get("$SObjectType.CurrentUser.Id")
                            }]);
                            var d = b.get("v.editNoteEnabled"),
                                f = b.get("v.editPanel");

There ya go. Hope this helps.

3
  • I finally got around to trying this out. It seems to work. Thank you so much for your time.
    – ashish n
    Apr 13, 2020 at 16:36
  • 2
    Just wanted to add something for the next person encountering this... If you want to populate the related record by default, pass this parameter: ``` let editEvent = $A.get("e.notes:editNote"); let params = { noteId: noteId, // don't save this if new note contextList: {id: parentId} // parent id is the default ContentDocumentLink }; editEvent.setParams(params); editEvent.fire(); ``` Apr 7, 2021 at 9:00
  • Another piece for whoever encounters this next... if you have a parent component A, dragged onto a lightning page, and A has a child component B, B cannot use $A.get("e.notes:editNote"); directly (it will return undefined). I used the answer here (salesforce.stackexchange.com/questions/217472/…) to have component A get the Event and return it, then called that function from B. Once you have the event, then use the rest of this answer. Jan 20, 2023 at 20:20

You must log in to answer this question.

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