+ Start a Discussion
Sonam PatilSonam Patil 

Insert Lead through JS

Hi,
for the code below I am getting the error as: Error: InsertLead Compile Error: Constructor not defined: [SelectOption].<Constructor>(String, String) at line 15 column 17.
Please Anyone help me in this issue.
code:
<apex:page controller="InsertLead" >
    
        <script type="text/javaScript">
        function Validate(){
        if(document.getElementById('{$component.LF.LDB.LName}').value==''||document.getElementById('{$component.LF.LDB.comp}').value==''){
        alert('Last Name and Company are the required fields');
        }
        else{
         callSubmitted();
         alert('Successfully Inserted');
        }
        }
        </script>
        <apex:form id="LF">
        <apex:actionFunction action="{!submitLead}" name="callSubmitted" reRender="LDB"/>
        <apex:pageBlock id="LDB">
       
        <table>
        <tr>
        <td><apex:outputText value="First Name"></apex:outputtext></td>
        <td><apex:inputText value="{!firstName}"/></td>
        </tr>
         <tr>
        <td><apex:outputText value="Last Name"></apex:outputtext></td>
        <td><apex:inputText value="{!lastName}" id="LName"/></td>
        </tr>
        <tr>
        <td><apex:outputText value="Company"></apex:outputtext></td>
        <td><apex:inputText value="{!company}" id="comp"/></td>
        </tr>
        <tr>
        <td><apex:outputText value="Lead Status"></apex:outputtext></td>
        <td><apex:selectList value="{!statusOption}">
        <apex:selectOptions value="{!items}"/>
        </apex:selectList></td>
        </tr>
        </table>
        <apex:commandButton value="Save" onclick="Validate();"/>
   
    </apex:pageBlock>
    </apex:form>
</apex:page>
------------------------------------------------
Controller Class:
public with sharing class InsertLead {

   // public String items { get; set; }

    public String statusOption { get; set; }

    public String company { get; set; }

    public String lastName { get; set; }

    public String firstName { get; set; }
    
    public Lead l = new Lead();
    public List<selectOption>  getItems(){
    List<selectOption> options= new List<selectOption>();
    options.add(new selectOption('Open- Not Contracted','Open-Not Contracted'));
    options.add(new SelectOption('Working-Contracted','Working-Contracted'));
    return options;
    }

    public PageReference submitLead() {
    l.FirstName=firstname;
    l.LastName=lastname;
    l.Company=company;
    l.Status=statusOption;
        return null;
    }

}
karthikeyan perumalkarthikeyan perumal
hello, 

use below code for your class, 
public with sharing class InsertLead {

   // public String items { get; set; }

    public String statusOption { get; set; }

    public String company { get; set; }

    public String lastName { get; set; }

    public String firstName { get; set; }
    
    public Lead l = new Lead();
    public List<selectOption>  getItems(){
    List<selectOption> options= new List<selectOption>();
    options.add(new SelectOption('None','-- Select --'));
    options.add(new selectOption('Open- Not Contracted','Open-Not Contracted'));
    options.add(new SelectOption('Working-Contracted','Working-Contracted'));
    return options;
    }

    public PageReference submitLead() {
    l.FirstName=firstname;
    l.LastName=lastname;
    l.Company=company;
    l.Status=statusOption;
        return null;
    }

}
Hope this will help you.

Thanks 
karthik 
 
Sonam PatilSonam Patil
hi Karthik,
It's showing the same error.
 
karthikeyan perumalkarthikeyan perumal
Hello, 

your code works fins with out have any change but very very minmal change not the error you have posted. i was able to insert the lead sucessfully using you code. 

in you page replace commapny button like below 

 <apex:commandButton value="Save" onclick="Validate();return false;"/>

in class

add insert statement code like below

public PageReference submitLead() {
    l.FirstName=firstname;
    l.LastName=lastname;
    l.Company=company;
    l.Status=statusOption;
    insert l;
    return null;
    }


with these changes i was able to insert Lead very sucessfully.  

Hope this will clear.  i dont see any error you have stated above. 

Thanks
karthik