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
sgsales forcesgsales force 

Lightning Page to fetch/create Lead record

Hey All Experts,

Looking to create a onepage Lightning component or Page. I am a newbie to SF
Would prefer if its doable via App Builder or declaratively.

1.Objective is to fetch existing Lead record (based on name,mobile)
and populate fields

2.If record doesnot exist it should give an option to create and 
save new lead record

Just want to keep it simple and stupid for the first version as 
long as basic functionality works.
Any clues y'all might be able to provide. Thank you so much in advance.

Regards,
Sunny
PriyaPriya (Salesforce Developers) 

Hi Sunny,

Kindly refer this article to search and create records from component. 
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/data_service_create_record.htm

 

https://developer.salesforce.com/docs/component-library/bundle/lightning:recordForm/documentation

 

Please mark it as best answer if it helps.

Regards,

Priya Ranjan

Adam Zuckerman 3Adam Zuckerman 3

Hey Sunny!

You should be able to this declaratively via a Flow and then embed the Flow on the Lightning page. I am almost want to suggest that you use the Lookup Flow Screen component (https://help.salesforce.com/s/articleView?id=sf.flow_ref_elements_screencmp_lookup.htm&type=5), but I don't think that will allow you to search by mobile (though it would be way simpler overall).

Absent that, the first step of the flow should allow the user to enter a name and phone number then you will use the get records flow element to get a collection of lead records.

If no results are returned, you send the user to a new flow screen which will allow for the entry of lead information.

If records are returned, you should load your lead record collection into a Record Choice Set which will allow the user to select the matching Lead record and then populate relevant fields.

A word of caution, the search might not be "fuzzy" enough for your needs and you'll probably want to split name into first name and last name. Phone numbers can also be inconsistently formatted so you might need a way to assure the phone number field used for comparison is in a consistent format (i.e. removing all parenthesis, hyphens, etc.) 

I hope that's enough to get you started. And good luck!