function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ramapoc nramapoc n 

Redirect To standard Edit Page on button cllick in Lightning

Hello All,  
in lightning When i click on custom button it will redirect to standard edit page of the object.   For this, I have created a
1. component which has button
2. Controller.js : which will fire the event

<aura:component controller="AccountLightningSearchclass" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global">
  <aura:attribute name="account" type="Account" default="{ 'sobjectType': 'Account'}"/> 
    <aura:registerEvent name="createRecordEvent" type="c:navigateToUrl"/>
    <aura:handler event="c:navigateToUrl" action="{!c.CreateAccount}" />
    <div class="slds-align--absolute-center">
                 <button type="Button" onclick="{!c.CreateAccount}" disabled="false" class="slds-button slds-button--brand">Create Account</button>
             </div>
</aura:component>

2. Controller:
CreateAccount : function(component, event, helper) {

           var createRecordEvent = $A.get("e.force:navigateToRecord");
        alert('Getting Event');
        createRecordEvent.setParams({
            "entityApiName": "Account"
        });
        createRecordEvent.fire();
        }, 
    
})

3. Event:
<aura:event type="APPLICATION" description="Event template" >

 <aura:attribute name="entityApiName" type="String"/>

</aura:event>

But Getting setparams undefined error.
 Thanks in advance
Best Answer chosen by ramapoc n
sfdcMonkey.comsfdcMonkey.com
hi ramapoc 
try to use force:editRecord standard event for Opens the page to edit the record specified by recordId.
go to below link for it 
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_force_editRecord.htm
i hope it helps you.
Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper soltuions for others
thanks 

http://sfdcmonkey.com  (http://sfdcmonkey.com )

All Answers

sfdcMonkey.comsfdcMonkey.com
hi ramapoc 
try to use force:editRecord standard event for Opens the page to edit the record specified by recordId.
go to below link for it 
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_force_editRecord.htm
i hope it helps you.
Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper soltuions for others
thanks 

http://sfdcmonkey.com  (http://sfdcmonkey.com )
This was selected as the best answer
ramapoc nramapoc n
Hi Piyush,

Thank you For your response. Actually I need to land on Create Page, Its my typo bad that i have mentioned Edit Page. Now I changed my code to below. Getting No error but when i click on Create Account button nothing happens. Do i need to register event in component or  i am missing something?

1. <aura:component controller="AccountLightningSearchclass" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global">
  <aura:attribute name="account" type="Account" default="{ 'sobjectType': 'Account'}"/> 
    <div class="slds-align--absolute-center">
                 <button type="Button" onclick="{!c.createRecord}" disabled="false" class="slds-button slds-button--brand">Create Account</button>
             </div>
</aura:component>

2. Controller:
({
createRecord : function (component, event, helper) {
    var createRecordEvent = $A.get("e.force:createRecord");
    createRecordEvent.setParams({
        "entityApiName": "Account"
    });
    createRecordEvent.fire();
}
})

 
ramapoc nramapoc n
In developer edition. Actually I am calling this component from VF page and override with Account New button with vf page.
Below is my complete code:

<aura:component controller="AccountLightningSearchclass"  access="global" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" >
   <ltng:require styles="{!$Resource.SLDS214 +'/assets/styles/salesforce-lightning-design-system.css'}"/>
   <aura:attribute name="searchResult" type="List" description="use for store and display Account list return from server"/>
   <aura:attribute name="searchKeyword" description="use for input" type="string" ></aura:attribute>
   <aura:attribute name="Message" type="boolean" default="false" description="use for display no record found message"/>
 <aura:attribute name="account" type="Account" default="{ 'sobjectType': 'Account'}"/> 
    <!--<aura:registerEvent name="createRecordEvent" type="c:createRecordEvent"/> -->
    <!--<aura:handler event="c:createRecord" action="{!c.createRecord}" /> -->
    
    <div class="slds-m-around--large">
         <form class="slds-form--inline"> 
            <div class="slds-form-element"> 
                    <label class="slds-form-element__label" for="Search">Account Search</label>  
                          <div class="slds-form-element__control" >
                              <ui:inputtext aura:id="searchId" value="{!v.searchKeyword}" placeholder="Type Account Name" required="true" class="slds-input"></ui:inputtext>
                         </div>
             </div>
             <div class="slds-form-element">
                 <button type="Button" id="buttn1" onclick="{!c.doSearch}" class="slds-button slds-button--brand">Search</button>
             </div>
    </form>
    </div>
    <div class="slds-m-around--large">
        <div class="slds-align--absolute-center">
                 <button type="Button" onclick="{!c.createRecord}" disabled="true" class="slds-button slds-button--brand">Create Account</button>
             </div>
        <table class="slds-table slds-table--bordered slds-table--cell-buffer">
            <thead>
                <tr class="slds-text-title--caps">
                    <th scope="col">
                         <div class="slds-truncate" title=" Name"> Name</div>
                    </th>   
               </tr>
            </thead>
            <tbody>
            <aura:if isTrue="{!v.Message}">
               <div class="slds-text-color--error"> No Result Found...</div>
            </aura:if>
                <aura:iteration items="{!v.searchResult}" var="acct"> 
              <tr>
                   <td>
                     <div class="slds-truncate">{!acct.Name}</div>
                  </td>
                  
              </tr>
                </aura:iteration>    
            </tbody>
        </table>
    </div>
</aura:component>

Controller:

({
    doSearch : function(component, event, helper) {
        var searchKeyId=component.find("searchId"); 
        var searchKey=component.get('v.searchKeyword');
        if(searchKey == '' || searchKey == null)
        {
            alert('enter');
            searchKeyId.set("v.errors",[{message: "Enter search Keyword" }]);  // If we add this error message slite deviation is for inputtext align
                $A.util.addClass(searchKeyId, 'errorClassAdd');
                 $A.util.removeClass(searchKeyId, 'errorClassRemove');
        }
        else{
             $A.util.addClass(searchKeyId, 'errorClassRemove');
             $A.util.removeClass(searchKeyId, 'errorClassAdd');
            helper.searchHelper(component,event);
        } 
    },

    
   createRecord : function (component, event, helper) {
    var createRecordEvent = $A.get("e.force:createRecord");
    createRecordEvent.setParams({"entityApiName": "Account"
    });
    createRecordEvent.fire();
},
}) 

Helper:
({
    searchHelper: function(component, event) {
        var action = component.get("c.getAccount");
        action.setParams({
            'searchstring': component.get("v.searchKeyword")         
        });
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                var storeResponse = response.getReturnValue();
                // if storeResponse size is 0 ,display no record found message on screen.
                if (storeResponse.length == 0) {
                    alert('size is 0');
                    component.set("v.Message", true);
                } else {
                    component.set("v.Message", false);
                
                }
                // set numberOfRecord attribute value with length of return value from server
                //component.set("v.numberOfRecord", storeResponse.length);
                // set searchResult list with return value from server.
                  component.set("v.searchResult", storeResponse);
                    alert('not success');
                    alert('==='+component.set("v.searchResult", storeResponse));
            } 
 
        });
        $A.enqueueAction(action);
 
    },
})

Apex class:

public with sharing class AccountLightningSearchclass {
  
   public list<Account> acc{get;set;}
   public  AccountLightningSearchclass(ApexPages.StandardController controller) {
    
   } 

  @AuraEnabled  
   public static List<Account> getAccount(string searchstring){  
     string searchquery2='select Name from Account where Name like \'%'+searchstring+'%\'  Limit 20';
     List<Account> acctlist = Database.query(searchquery2); 
     return acctlist;
     }
    
Vf Page:

<apex:page standardcontroller="Account">
    <!-- This page is a host page for the call report lightning component. -->
    <apex:includeLightning />
    <script>
        var recordId = '{!Account.id}';
        // c:VFPAccountSearch implements force:hasRecordId and requires the call report ID
        $Lightning.use("c:VFPSearchApp", function() {
          $Lightning.createComponent('c:VFPAccountSearch',
              { recordId : recordId },
              'Account',
              function(cmp) {
                // do some stuff
               console.log('component created');
              });
        });
        
    </script>
 
sfdcMonkey.comsfdcMonkey.com
hi
$A.get("e.force:createRecord"); -->
This event is handled by the one.app container. It’s supported in Lightning Experience and Salesforce1 only. This event presents a standard page to create a record. That is, it doesn’t respect overrides on the object’s create action.
and there is also many limitation for embedded lightning component + vf page so i will suggest you to that create a lightning component and add this component on lightning experience page layout you can also add this component with quick action button on lightning exper.
read below trailhead modual also
https://trailhead.salesforce.com/en/lex_javascript_button_migration/lex_javascript_button_migration_intro
https://trailhead.salesforce.com/en/module/lex_dev_visualforce
i hope it helps you.
Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper soltuions for others
thanks 
ramapoc nramapoc n
Hi Piyush,

Thank You for your support. In the above , You told me to add component to page layout. i am not sure how can i add component to page layout? is there any way to add component to page layout. can you please help me on that. As of now it is working  after creating tab for lightning component.
david willy 1david willy 1
I enjoyed over read your blog post. Your blog has nice information, I got good ideas from this amazing blog. I am always searching like this type of blog post. I hope I will see again www.dumpsexpert.com/1z0-997-Exam-Dumps.html