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
Marvin Castro 8Marvin Castro 8 

Help on Visual Force Page

Hi - I'm new to creating VF pages in salesforce.  I created a simple lead form that captures basic profile information.  I'm having issues with special character on the Company name and/or the city fields on the Lead object. It appears it doesn't save the record in this scenario - Company Name Re/Max Unlimited  City:  San Antonio

Here's the apex code for the page:

<apex:page standardController="Lead">
<apex:form >
    <apex:pageBlock mode="edit">
        <p/>
        <p/>
           <div align="center" draggable="false" >
        <apex:commandbutton action="{!save}" value="Save"/>
        <apex:commandbutton action="{!cancel}" value="Cancel"/>
        </div>
        <p/>
      
        <apex:pageBlockSection title="Lead Information" columns="1">
            <apex:inputField value="{!Lead.Salutation}"/>
            <apex:inputField value="{!Lead.FirstName}" required="true"/>
             <apex:inputField value="{!Lead.LastName}"/>
            <apex:inputField value="{!Lead.Suffix}"/>
            <apex:inputField value="{!Lead.Company}"/>       
 </apex:pageBlockSection>
 </apex:pageBlock>       
 <p/>
    <apex:pageBlock mode="edit">
        <apex:pageBlockSection title="Contact Information" columns="1">
                   <apex:inputField value="{!Lead.Email}" required="true"/>
                    <apex:inputField value="{!Lead.Phone}" required="true"/>
                    <apex:inputField value="{!Lead.MobilePhone}"/>
                    <apex:inputField value="{!Lead.Street}"/>
                    <apex:inputField value="{!Lead.City}" required="true"/>
                    <apex:inputField value="{!Lead.state}" required="true"/>
                    <apex:inputField value="{!Lead.postalcode}"/>
                    <p/>     
 </apex:pageBlockSection>
 </apex:pageBlock>   
</apex:form>
</apex:page>

I appreciate any assistance.

Thanks,

Marvin 
Best Answer chosen by Marvin Castro 8
Onesh ReddyOnesh Reddy
Marvin,

Try the Below code.Its working fine.Make sure you dont have any Validation rules on fields.
<apex:page standardController="Lead">
<apex:form >
    <apex:pageBlock mode="edit">
        <p/>
        <p/>
           <div align="center" draggable="false" >
        <apex:commandbutton action="{!save}" value="Save"/>
        <apex:commandbutton action="{!cancel}" value="Cancel"/>
        </div>
        <p/>
      
        <apex:pageBlockSection title="Lead Information" columns="1">
            <apex:inputField value="{!Lead.Salutation}"/>
            <apex:inputField value="{!Lead.FirstName}" required="true"/>
             <apex:inputField value="{!Lead.LastName}"/>
            <apex:inputField value="{!Lead.Company}"/>       
 </apex:pageBlockSection>
 </apex:pageBlock>       
 <p/>
    <apex:pageBlock mode="edit">
        <apex:pageBlockSection title="Contact Information" columns="1">
                   <apex:inputField value="{!Lead.Email}" required="true"/>
                    <apex:inputField value="{!Lead.Phone}" required="true"/>
                    <apex:inputField value="{!Lead.MobilePhone}"/>
                    <apex:inputField value="{!Lead.Street}"/>
                    <apex:inputField value="{!Lead.City}" required="true"/>
                    <apex:inputField value="{!Lead.state}" required="true"/>
                    <apex:inputField value="{!Lead.postalcode}"/>
                    <p/>     
 </apex:pageBlockSection>
 </apex:pageBlock>   
</apex:form>
</apex:page>

Best Regards,
Onesh.K

All Answers

Onesh ReddyOnesh Reddy

Hi Marvin,

Your VisualForce page is almost correct except the line  <apex:inputField value="{!Lead.Suffix}"/>. There is no standard field named Suffix in Lead Object. Incase you have created a new field in lead object, use the API name of the field.(API name looks like Suffix__c).
1) Try <apex:inputField value="{!Lead.Suffix__c}"/> if u have created a custom field Suffix.
2) OR Remove the line <apex:inputField value="{!Lead.Suffix}"/>

Let me know if it helps you.

Best Regards,
Onesh.K

Marvin Castro 8Marvin Castro 8
Onesh,

Thanks for the response!   I removed the Suffix line and the record is still not saving.

Marvin
Onesh ReddyOnesh Reddy
Could you mention the error message displayed in Visualforce page or error message encountered while saving.
Onesh ReddyOnesh Reddy
Marvin,

Try the Below code.Its working fine.Make sure you dont have any Validation rules on fields.
<apex:page standardController="Lead">
<apex:form >
    <apex:pageBlock mode="edit">
        <p/>
        <p/>
           <div align="center" draggable="false" >
        <apex:commandbutton action="{!save}" value="Save"/>
        <apex:commandbutton action="{!cancel}" value="Cancel"/>
        </div>
        <p/>
      
        <apex:pageBlockSection title="Lead Information" columns="1">
            <apex:inputField value="{!Lead.Salutation}"/>
            <apex:inputField value="{!Lead.FirstName}" required="true"/>
             <apex:inputField value="{!Lead.LastName}"/>
            <apex:inputField value="{!Lead.Company}"/>       
 </apex:pageBlockSection>
 </apex:pageBlock>       
 <p/>
    <apex:pageBlock mode="edit">
        <apex:pageBlockSection title="Contact Information" columns="1">
                   <apex:inputField value="{!Lead.Email}" required="true"/>
                    <apex:inputField value="{!Lead.Phone}" required="true"/>
                    <apex:inputField value="{!Lead.MobilePhone}"/>
                    <apex:inputField value="{!Lead.Street}"/>
                    <apex:inputField value="{!Lead.City}" required="true"/>
                    <apex:inputField value="{!Lead.state}" required="true"/>
                    <apex:inputField value="{!Lead.postalcode}"/>
                    <p/>     
 </apex:pageBlockSection>
 </apex:pageBlock>   
</apex:form>
</apex:page>

Best Regards,
Onesh.K
This was selected as the best answer
Marvin Castro 8Marvin Castro 8
Can you please check if this is working for you in this specific scenario (it works in other scenarios - For example, if I remove the special character "/" in the Company)?  

First Name:  David
Last Name: Castillo Test
Company: Re/Max Unlimited
Email: davidcastillo@remax.com
Phone: (713) 561-7925
City: San Antonio
State/Provice: TX

When I save this record - it loops to the VF page without any error messages.

Thanks,

Marvin
Onesh ReddyOnesh Reddy
Marvin,
Lead is created from the VF page witout any errors, for the info provided above. The Company field accepts Special character. Maybe there is a validation rule on Company field preventing the entry of special character. 
If possible share your Developer org credentials to my mailid : oneshreddy@gmail.com so that i can have deep glance on.

Thanks,
Onesh.K