I'm trying to insert a custom object from a public visualforce, with a custom controller, the insertion is working fine, but then I realize that the fields aren't being inserted. So anybody could help me with this? My code is this by now: Visualforce Page

<apex:page Controller="PublicFormCarsyncController">
<apex:sectionHeader title="Información"/>
<apex:form >
    <apex:pageBlock title="Informacion de Vehiculo" mode="edit">
        <apex:pageBlockButtons >
            <apex:commandButton action="{!SaveMethod}" value="Guardar" immediate="true"/>
        <apex:pageBlockSection title="Campos Generales" columns="2">
            <apex:inputField id="placa" value="{!veh.Placa__c}" required="True" />
            <apex:inputField id="vehicleNumChasis" value="{!veh.Numero_de_Chasis__c}"/> 
            <apex:inputField id="vehicleNumMotor" value="{!veh.Numero_de_Motor__c}"/>
            <apex:inputField id="vehicleDivisa" value="{!veh.CurrencyIsoCode}"/>                    
            <!--Campos extras-->
        <apex:pageBlockSection title="Campos de Instalación" columns="2">
           <apex:inputField id="vehicleCilindraje" value="{!veh.Cilindraje_de_Veh_culo__c}"/>   
           <apex:inputField id="vehicleLugarInstalacion" value="{!veh.Lugar_de_Instalaci_n__c}"/>
           <apex:inputField id="vehicleContactInstalacion" value="{!veh.Celular_Contacto_Instalaci_n__c}"/>
           <apex:inputField id="vehicleNumOdvInstalacion" value="{!veh.Numero_Orden_de_la_Aplicaci_n__c}"/>   
           <apex:inputField id="vehicleFechaInstalacion" value="{!veh.Fecha_Instalaci_n__c}"/>
        <apex:pageBlockSection title="Valores" columns="2">                
            <apex:inputField id="vehicleValCredito" value="{!veh.Valor_del_Credito__c}"/>
            <apex:inputField id="vehicleValorSeguro" value="{!veh.Valor_del_Seguro__c}"/>
            <apex:inputField id="vehicleCostoSaneamiento" value="{!veh.Costo_de_saneamiento__c}"/>
        <apex:pageMessages />


public class PublicFormCarsyncController {  
Public Vehicle__c veh = new Vehicle__c();
Public String Placa {get; set;}
Public String vehicleNumChasis {get; set;}
Public String vehicleNumMotor {get; set;}
Public String vehicleCilindraje {get; set;}
Public DateTime vehicleFechaInstalacion {get; set;}
Public String vehicleLugarInstalacion {get; set;}
Public String vehicleContactInstalacion {get; set;}
Public String vehicleNumOdvInstalacion {get; set;}
Public Decimal vehicleValCredito {get; set;}
Public Decimal vehicleValorSeguro {get; set;}
Public Decimal vehicleCostoSaneamiento {get; set;}
Public String vehicleDivisa {get; set;}
public Vehicle__c getveh()
    return veh;

public PublicFormCarsyncController(){}

public PageReference SaveMethod()
    insert veh;
    PageReference reRend = new PageReference('/Correcto');
    return reRend;



1 Answer 1


I recreated your entire page in my sandbox and then ran some tests. The short answer is you need to remove the immediate flag from your button as it's causing the save action to be called before the fields are submitted to the server.

This may be a matter of preference, but I cleaned up your controller in my sandbox as well (shouldn't impact functionality but is more inline what SF best practices).

public class PublicFormCarsyncController {  
Public Vehicle__c veh {
    get {
        if (veh == null) {
            veh = new Vehicle__c();

        return veh;


public PageReference SaveMethod () {       
    insert veh;
    PageReference reRend = new PageReference('/Correcto');
    return reRend;

I removed the random variables that didn't seem to apply (if they do apply, they don't apply to the code you provided).

Then, I modified your veh declaration to make it more inline with SF best practices.

Security for Public Profiles

  1. From Setup, enter Sites in the Quick Find box, then select Sites.
  2. Click the name of the site you want to control.
  3. Click Public Access Settings to open the Profile page for your site profile.

Once your on that page it's like working with a normal profile. Make sure that profile has all the field and object security you expect it to have.

You must log in to answer this question.

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