Carry out the following steps to develop a Lightning JavaScript Helper which is used for searching accounts, using the Salesforce Developer Console:
- Click on the Setup gear icon, as shown in the following screenshot:
The Setup gear icon is located in the top right-hand area of the main Home page.
- Click the Developer Console option, as shown in the following screenshot:
- In the resulting Developer Console window, open the resource or click on the tab for the Lightning Component accountSearchBeforeCreate.cmp.
- Click on HELPER (or press Ctrl + Shift + 3), as shown in the following screenshot:
- In the resulting Lightning JavaScript Helper edit page, paste the following code:
({ SearchHelper: function(component, event) { var action = component.get("c.getAccounts"); action.setParams({'psSearchText':
component.get("v.searchString") }); action.setCallback(this, function(response) { var state = response.getState(); if (state === "SUCCESS") { var returnValue = response.getReturnValue(); // if nothing is returned allow user to create an
account. if (returnValue.length == 0) { component.set("v.createStatus", true); }
else { component.set("v.createStatus", false); } // Set the Component attributes component.set("v.searchCounts",
returnValue.length); component.set("v.searchResult", returnValue); } }); $A.enqueueAction(action); }, })
- Click on File.
- Click on Save, as shown in the following screenshot: