Problem Statement - Lightning form in force.com sites not inserting lead records. I had to create a Web to lead form in lightning and host it in force.com sites. Since force.com sites can include only visualforce pages, I created a VF page and included a lightning component in it. When I submit the form via force.com sites, it does not insert the record and no error is returned. However, if I host this same lightning component as a standalone component on Account layout, the records are getting inserted.

Visualforce page -

<apex:page standardStylesheets="false" showHeader="false" sidebar="false" standardController="Lead" >
   <apex:includeLightning />
    <div id="lightning" />
    $Lightning.use("c:InquiryFormApp",    // name of the Lightning app
        function() {                  // Callback once framework and app loaded
                "c:createLeadRecord", // top-level component of your app
                { },                  // attributes to set on the component when created
                "lightning",   // the DOM location to insert the component
                function(cmp) {
                    // callback when component is created and active on the page
        '/AppInquiry'  // Community endpoint

Lightning App -

<aura:application access="GLOBAL" extends="ltng:outApp" implements="ltng:allowGuestAccess">
    <aura:dependency resource="c:createLeadRecord"/> 

Lightning component -

<!-- Include Static Resource-->

<!-- Define Attribute-->
<aura:attribute name="candidate" type="Lead" default="{'sobjectType': 'Lead',
                     'LastName': ''
<div class="container-fluid">
    <h3>Please Enter The Candidate Information</h3>

    <div class="form-group">
        <label>Last Name</label>
        <ui:inputText class="form-control" value="{!v.candidate.LastName}"/>

<div class="col-md-4 text-center">
    <ui:button class="btn btn-default" press="{!c.create}">Create</ui:button>

Lightning component controller -

    create : function(component, event, helper) {
        console.log('Create record');
        //getting the candidate information
        var candidate = component.get("v.candidate");
        //Calling the Apex Function
        var action = component.get("c.createRecord");
        //Setting the Apex Parameter
            candidate : candidate

        //Setting the Callback
            //get the response state
            var state = a.getState();
            //check if result is successfull
            if(state == "SUCCESS"){
                //Reset Form
                var newCandidate = {'sobjectType': 'Lead',
                                    'LastName': ''
                //resetting the Values in the form
                alert('Record is Created Successfully');
            } else if(state == "ERROR"){
                alert('Error in calling server side action');

        //adds the server-side action to the queue        


Apex controller -

global class CreateLeadRecord {
   * Create a new candidate Record
   * @param Candidate__c candidate  candidate record to be inserted
    public static void createRecord (Lead candidate){

            System.debug(': CreateCandidateRecord::createRecord::candidate'+candidate);

            if(candidate != null){
                insert candidate;

        } catch (Exception ex){
            system.debug(': exception is-'+ex.getMessage());
        //return candidate.Id;

Please suggest something by which I'll be able to create a Web to Lead form using Lightning and Force.com Sites.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.