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
bingi crm 7bingi crm 7 

we are crate a vf page when save button click they are automatically convert to account and contact relationship fields create they are showing error

i am writing the visual force using extension on the page they are showing the required filed has missing wTHIS IS VF PAGESHOW ERROR MESSAGE 
public class leaddetails {
    public lead leads{set;get;}
    public lead lead{set;get;}
    public leaddetails(ApexPages.StandardController controller){
        leads =(lead)controller.getRecord();
    }
    public pageReference createLead(){
        if(leads.name!=null){
            account acc=new account();
            acc.Name=lead.name;
            acc.Parentid= lead.company;
            acc.AnnualRevenue=lead.AnnualRevenue;
            acc.Fax=lead.Fax;
            acc.Type='Other';
            acc.Phone=lead.MobilePhone;
            acc.Industry=lead.Industry;
            insert acc;
            contact con=new contact();
             con.lastName=lead.lastName;
            con.firstName=lead.firstName;
            con.Description=lead.Industry;
            con.Title=acc.Name;
            con.Email=lead.Email;
            con.Phone=lead.MobilePhone;
            insert con;
             pageReference p=new pageReference('/'+acc.id);
            return p;
         }else{
        Insert leads;
         pageReference p=new pageReference('/'+leads.id);
            return p;

}
   }
    public void cancelLead(){
        lead=null;
    }
}
 
Best Answer chosen by bingi crm 7
Rohit Sharma 66Rohit Sharma 66
VF page seems fine:

<apex:page standardController="lead" extensions="leaddetails1" >
    <apex:form >
    <apex:pageBlock title="lead">
        <apex:pageBlockButtons location="bottom">
        <apex:commandButton value="save" action="{!createLead}"/>
        <apex:commandButton value="Cancel" action="{!cancelLead}"/>   
        </apex:pageBlockButtons>
        
        <apex:pageBlockSection >
        <apex:inputField value="{!lead.Company}"/>
        <apex:inputField value="{!lead.Email}"/>
        <apex:inputField value="{!lead.Fax}"/>
        <apex:inputField value="{!lead.Industry}"/>
        <apex:inputField value="{!lead.MobilePhone}"/>
        <apex:inputField value="{!lead.Name    }"/>
        <apex:inputField value="{!lead.AnnualRevenue}"/>
        <apex:inputField value="{!lead.Phone}"/>
        <apex:inputField value="{!lead.FirstName}"/>
        <apex:inputField value="{!lead.LastName}"/>
        <apex:inputField value="{!lead.status}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
    </apex:form>
</apex:page>

Paste the following apex code, its working for me:

public with sharing class leaddetails1 {
    
    public lead lead{set;get;}
    public leaddetails1(ApexPages.StandardController controller){
        lead = new lead();
    }

    public pageReference createLead(){
        if(lead.LastName != null && lead.Lastname != ''){
            account acc = new account();
            acc.Name=lead.LastName; // adding only required field, u can add more if you want
            insert acc;
            
            contact con=new contact();
            con.lastName = lead.lastName;
            con.AccountId = acc.Id; // attaching contact to the Account created
            insert con;
            
            pageReference p = new pageReference('/'+acc.id);
            return p;
         }
         else{
             Insert lead;
             pageReference p=new pageReference('/'+lead.id);
             return p;

        }
    }
    
    public void cancelLead(){
        lead=null;
    }
}

Please let me know if it works.

All Answers

Rohit Sharma 66Rohit Sharma 66
Please try the following code: 
In acc.ParentId u need to pass the Account Id, not the Account Name. The field u have taken for the company Name is Text field, it wont take Id in back-end. U can query the Account Id base on the value of Company Name and put that Id in the ParentId.

public class leaddetails {
    public lead leads{set;get;}
    public lead lead{set;get;}
    public leaddetails(ApexPages.StandardController controller){
        leads =(lead)controller.getRecord();
    }
    public pageReference createLead(){
        if(leads.LastName != null && leads.Lastname != ''){
            account acc = new account();
            acc.Name=lead.LastName;
            acc.Parentid = lead.company; // here u need to pass the id of the Account, not the name
            acc.AnnualRevenue=lead.AnnualRevenue;
            acc.Fax=lead.Fax;
            acc.Type='Other';
            acc.Phone=lead.MobilePhone;
            acc.Industry=lead.Industry;
            insert acc;
			
            contact con=new contact();
            con.lastName = lead.lastName;
            con.firstName=lead.firstName;
            con.Description=lead.Industry;
            con.Title=acc.Name;
            con.Email=lead.Email;
            con.Phone=lead.MobilePhone;
            insert con;
             pageReference p=new pageReference('/'+acc.id);
            return p;
         }else{
        Insert leads;
         pageReference p=new pageReference('/'+leads.id);
            return p;

}
   }
    public void cancelLead(){
        lead=null;
    }
}

Let me know if you find any issues.

 
bingi crm 7bingi crm 7
issues hit this error
Rohit Sharma 66Rohit Sharma 66
Please paste the code for your vf page as well. Expecting that u are putting data in all the field before clicking the save button.
bingi crm 7bingi crm 7
i don't want parentid . when lead fields insert the values click on the save button automatically create account and contact this is vf page code
Rohit Sharma 66Rohit Sharma 66
Please paste the vf code.
bingi crm 7bingi crm 7
<apex:page standardController="lead" extensions="leaddetails1" >
    <apex:form >
    <apex:pageBlock title="lead">
        <apex:pageBlockButtons location="bottom">
        <apex:commandButton value="save" action="{!createLead}"/>
        <apex:commandButton value="Cancel" action="{!cancelLead}"/>   
        </apex:pageBlockButtons>
        <apex:pageBlockSection >
        <apex:inputField value="{!lead.Company}"/>
        <apex:inputField value="{!lead.Email}"/>
        <apex:inputField value="{!lead.Fax}"/>
        <apex:inputField value="{!lead.Industry}"/>
        <apex:inputField value="{!lead.MobilePhone}"/>
        <apex:inputField value="{!lead.Name    }"/>
        <apex:inputField value="{!lead.AnnualRevenue}"/>
        <apex:inputField value="{!lead.Phone}"/>
        <apex:inputField value="{!lead.FirstName}"/>
        <apex:inputField value="{!lead.LastName}"/>
        <apex:inputField value="{!lead.status}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
    </apex:form>
</apex:page>
Rohit Sharma 66Rohit Sharma 66
VF page seems fine:

<apex:page standardController="lead" extensions="leaddetails1" >
    <apex:form >
    <apex:pageBlock title="lead">
        <apex:pageBlockButtons location="bottom">
        <apex:commandButton value="save" action="{!createLead}"/>
        <apex:commandButton value="Cancel" action="{!cancelLead}"/>   
        </apex:pageBlockButtons>
        
        <apex:pageBlockSection >
        <apex:inputField value="{!lead.Company}"/>
        <apex:inputField value="{!lead.Email}"/>
        <apex:inputField value="{!lead.Fax}"/>
        <apex:inputField value="{!lead.Industry}"/>
        <apex:inputField value="{!lead.MobilePhone}"/>
        <apex:inputField value="{!lead.Name    }"/>
        <apex:inputField value="{!lead.AnnualRevenue}"/>
        <apex:inputField value="{!lead.Phone}"/>
        <apex:inputField value="{!lead.FirstName}"/>
        <apex:inputField value="{!lead.LastName}"/>
        <apex:inputField value="{!lead.status}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
    </apex:form>
</apex:page>

Paste the following apex code, its working for me:

public with sharing class leaddetails1 {
    
    public lead lead{set;get;}
    public leaddetails1(ApexPages.StandardController controller){
        lead = new lead();
    }

    public pageReference createLead(){
        if(lead.LastName != null && lead.Lastname != ''){
            account acc = new account();
            acc.Name=lead.LastName; // adding only required field, u can add more if you want
            insert acc;
            
            contact con=new contact();
            con.lastName = lead.lastName;
            con.AccountId = acc.Id; // attaching contact to the Account created
            insert con;
            
            pageReference p = new pageReference('/'+acc.id);
            return p;
         }
         else{
             Insert lead;
             pageReference p=new pageReference('/'+lead.id);
             return p;

        }
    }
    
    public void cancelLead(){
        lead=null;
    }
}

Please let me know if it works.
This was selected as the best answer
Rohit Sharma 66Rohit Sharma 66
Please mark this as best answer if worked.
bingi crm 7bingi crm 7
yaa its working thank you
bingi crm 7bingi crm 7
hi 1) i have scenario product name , price , quantity , total price and quantity = total ex:- 100 * 2 = 200 2) on that page create check box if you click the check box any select the record those select record they display on downside i am try to first record dispaly if you check the check box they showing the record but i am unable to showing record -
bingi crm 7bingi crm 7
class