0

VF code

<apex:page standardController="Lead" extensions="Leadclass">
    <apex:form >
        
        <apex:pageBlock title="lead">
       <apex:pageBlockSection title="enter" columns="2">
           
               <apex:inputField  label="FirstName" value="{!forleadfirst}"/>
               <apex:inputField  label="LastName" value="{!forleadlast}"/>
               <apex:commandButton value="save" Action="{!mysave}"/>
           </apex:pageBlockSection>
           
        </apex:pageBlock>
      
   </apex:form>
</apex:page>

Class

public class Leadclass {
    public static string message{get;set;}
    public static string forleadfirst{get;set;}
    public static string forleadlast{get; set;}
   
    public Leadclass(Apexpages.StandardController stdcontroller){
        
    }
    public static void showgreeting(){
        message = 'Welcome';
    }
    public void mysave(){
        Lead newLead = new Lead();
        newLead.FirstName = forleadfirst;
        newLead.LastName=forleadlast;
        newLead.Status = 'Open';
        newLead.Phone = '0423465434';
        insert newLead;
        
    }
}

enter image description here

1 Answer 1

0

<apex:inputField> expects to be bound to an sObject field to determine the metadata, and thus how to render the field. You can either use a normal <apex:inputText> instead, or bind to an instance of a Lead.


Option 1

<apex:inputText  label="FirstName" value="{!forleadfirst}"/>

Option 2

public class Leadclass {
    public static string message{get;set;}
    Lead record;
    ApexPages.StandardController controller;
   
    public Leadclass(Apexpages.StandardController stdcontroller){
        record = (Lead)stdcontroller.getRecord();
        controller = stdcontroller;
    }
    public static void showgreeting(){
        message = 'Welcome';
    }
    public void mysave(){
        record.Status = 'Open';
        record.Phone = '0423465434';
        controller.save();
    }
}

<apex:inputField value="{!Lead.FirstName}"/>

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .