Open a record create or edit page, or navigate to a record in salesforce lightning

force:createRecord:

 To create a new record:
createRecord : function (component, event, helper) {
    var createRecordEvent = $A.get("e.force:createRecord");
    createRecordEvent.setParams({
        "entityApiName": "Contact"
    });
    createRecordEvent.fire();
}

force:editRecord

To Edit a existing record:

editRecord : function(component, event, helper) 
    var editRecordEvent = $A.get("e.force:editRecord");
    editRecordEvent.setParams({
      "recordId": component.get("v.contact.Id")
   });
    editRecordEvent.fire();
}

force:navigateToList

To navigate to a list view, set the list view ID on the listViewId attribute and fire the event.

gotoList : function (component, event, helper) {
    var action = component.get("c.getListViews");
    action.setCallback(this, function(response){
        var state = response.getState();
        if (state === "SUCCESS") {
            var listviews = response.getReturnValue();
            var navEvent = $A.get("e.force:navigateToList");
            navEvent.setParams({
                "listViewId": listviews.Id,
                "listViewName": null,
                "scope": "Contact";
            });
            navEvent.fire();
        }
    });
    $A.enqueueAction(action);
}

This Apex controller returns all list views for the contact object

@AuraEnabled
public static List<ListView> getListViews() {
    List<ListView> listviews = 
        [SELECT Id, Name FROM ListView WHERE SobjectType = 'Contact'];
     // Perform isAccessible() check here
    return listviews;
}

force:navigateToObjectHome

Navigates to the object home specified by the scope attribute.

navHome : function (component, event, helper) {
    var homeEvent = $A.get("e.force:navigateToObjectHome");
    homeEvent.setParams({
        "scope": "myNamespace__myObject__c"
    });
    homeEvent.fire();
}

force:navigateToRelatedList

 Navigates to the related list specified by parentRecordId.
gotoRelatedList : function (component, event, helper) {
    var relatedListEvent = $A.get("e.force:navigateToRelatedList");
    relatedListEvent.setParams({
        "relatedListId": "Cases",
        "parentRecordId": component.get("v.contact.Id")
    });
    relatedListEvent.fire();
}

force:navigateToSObject

Navigates to an sObject record specified by recordId.

createRecord : function (component, event, helper) {
    var navEvt = $A.get("e.force:navigateToSObject");
    navEvt.setParams({
      "recordId": "00QB0000000ybNX",
      "slideDevName": "related"
    });
    navEvt.fire();
}

force:navigateToURL

 Navigates to the specified URL.

1)   Using a relative URL.

gotoURL : function (component, event, helper) {
    var urlEvent = $A.get("e.force:navigateToURL");
    urlEvent.setParams({
      "url": "/006/o"
    });
    urlEvent.fire();
}

2)   Using external website when the link is clicked.

navigate : function(component, event, helper) {
  
    //Find the text value of the component with aura:id set to "address"
    var address = component.find("address").get("v.value");
    var urlEvent = $A.get("e.force:navigateToURL");
    urlEvent.setParams({
      "url": 'https://www.google.com/maps/place/' + address
    });
    urlEvent.fire();
}
Advertisements

5 thoughts on “Open a record create or edit page, or navigate to a record in salesforce lightning

    • I think you are missing salesforce lightning design system CSS file or may be missed “slds” class. If you will send me code for the same than I can tell you what is the actually missing.

      Like

  1. Hi
    thank you for the reply.
    I have passes event as parameter, please find below my controller function :-

    editRecord : function(component, event, helper) {
    console.log(“inside editRecord”);
    var selectedItem = event.currentTarget;
    var index = selectedItem.dataset.record;
    var selectedCampingItem = component.get(“v.items”)[index];
    console.log(“Id : “+selectedCampingItem.Id);

    var editRecordEvent = $A.get(“e.force:editRecord”);
    console.log(“editRecordEvent : “+editRecordEvent);
    editRecordEvent.setParams({
    “recordId”: selectedCampingItem.Id
    });
    editRecordEvent.fire();
    },

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s