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
AppeltAppelt 

Error inserting lead

I am trying to create a new lead from inside an Apex Controller. For test purposes, I am simply running the following code:

insert new Lead(LastName='Smite', Company='Acme');

This works fine when run from an execure anonymous window, but when it runs in my controller I always get:

System.DmlException: Insert failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, invalid parameter value: []
Error is in expression '{!createLead}' in component <apex:commandButton> in page prospects

Why would this be happending? I have no triggers or workflows defined. 

Any help is greatly appreciated.
Vamsi KrishnaVamsi Krishna
can you post your controller method code ?

also can you try changing the line to

Lead l = new Lead(LastName='Smite', Company='Acme');
insert l;
AppeltAppelt
That basically is my entire method now. Here it is:

public PageReference createLead() { 
    	Lead l = new Lead(LastName='smith', Company='Acme');
        insert l;
        System.debug('New Lead Created');
        return null;
    }


hemant ranahemant rana
Hi its inserting the lead records. Its very basic code may be it will help....


Page----

<apex:page controller="isertLead">
<apex:form >
<apex:inputText value="{!Lname}" label="Lname"/>
<apex:inputText value="{!Status}" label="Status"/>
<apex:inputText value="{!Company}" label="Company"/>
<apex:commandButton action="{!save}" value="save"/>

</apex:form>

 
</apex:page>
Controller--------------
public class isertLead {
public string Lname{get;set;}
public string Status{get;set;}
public string Company{get;set;}

public void save()
{
Lead l=new Lead();
l.lastname=Lname;
l.Status=Status;
l.Company=Company;
insert l;
}
}