You need to sign in to do that
Don't have an account?

Best Practice For Custom Logic to suggest accounts and contacts?
I'm creating a lightning component that has input fields(name firstname,lastname, phone, email etc.)
I have it so that it runs a sosl query on change for any of those fields. (runs a sosl on change of the input field)
My question is - What do you consider the best practice on this? It seems to me that running a query on every keystroke can be very expensive in terms of api calls. I looked at google.com and saw they have a time delay. What do you guys suggest? I'll put a few code snippets below:
Component
<lightning:input onchange="{!c.inputChange}" aura:id="fname" label="First Name" value="{!v.SelectedCustomer.FirstName}" />
JsController:
inputChange: function(component, event, helper) { var action = component.get('c.suggestAccountsContacts'); action.setParams({ 'name' : component.get('v.SelectedCustomer').Name, 'fName': component.get('v.SelectedCustomer').FirstName, 'lName': component.get('v.SelectedCustomer').LastName, 'phone': component.get('v.SelectedCustomer').Phone, 'email': component.get('v.SelectedCustomer').PersonEmail }); action.setCallback(this, function(response) { var state = response.getState(); if (component.isValid() && state === 'SUCCESS') { component.set('v.Customers', response.getReturnValue()); } else { console.log('Failed with state: ' + state); } }); $A.enqueueAction(action); },Apex:
public static Object ... { ... //Build filter string Return [FIND :filter IN ALL FIELDS RETURNING Contact(Id, RecordTypeId, IsPersonAccount, AccountId, Name, Firstname, LastName, Email, Phone), ACCOUNT(ID, IsPersonAccount, RecordTypeId, Name, FirstName, LastName, PersonEmail ,PHONE)]; }
In order to query every time, you can query the object by using SOQL once and store it in a list attribute in the component, so that you can check for the new input with that attribute values.