I have a custom visualforce page that has the Product2 standard controller and a class as extension. The objective here is to make it possible to enter the product information, and the user can click "Save and New", and the page will reload after inserting a new product with the informations that were typed in.
The issue I'm having right now is that even though I get all the fields from the visualforce page using the inputField
markup, Salesforce keeps throwing me an error saying that a required field is missing. However this field is set (I can even check it being set using System.debug on the object, just right before the insertion).
Since I can check that the object has all the necessary fields using the debug feature, I would like to know if I'm missing something here, or if this is a bug?
The code is as follows:
<apex:page showHeader="true" sidebar="true" standardController="Product2" extensions="CadastroProdutosController">
<!-- Name: CriaMultiplosProdutos -->
<apex:pageMessages/>
<apex:form>
<apex:pageBlock>
<apex:pageBlockSection title="Novo Produto" collapsible="false" columns="2">
<apex:inputField value="{!prod.ProductCode}" label="Código do Produto" required="true"/>
<apex:inputField value="{!prod.Fabricante__c}" label="Fabricante" required="true"/>
<apex:inputField value="{!prod.Modelo_do_produto__c}" label="Modelo do Produto"/>
<apex:inputField value="{!prod.Description}" label="Descrição" required="true"/>
<apex:inputField value="{!prod.regimeEspecial__c}" label="Regime Especial"/>
<apex:inputField value="{!prod.Family}" label="Família de Produtos" required="true"/>
<apex:inputField value="{!prod.Observacao__c}" label="Observação"/>
<apex:inputField value="{!prod.Ativo__c}" label="Ativo"/>
<apex:inputField value="{!prod.Fabricante_Codigo_do_produto__c}" label="Fabricante + Código do Produto"/>
</apex:pageBlockSection>
<apex:pageBlockButtons>
<apex:commandButton action="{!mySave}" value="Salvar"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
And the controller:
public with sharing class CadastroProdutosController
{
public ApexPages.StandardController controller;
public Product2 prod {get;set;}
public CadastroProdutosController(ApexPages.StandardController stdController)
{
this.controller = stdController;
this.prod = new Product2();
}
public PageReference mySave()
{
try
{
System.debug(this.prod);
insert this.prod;
return new PageReference('/apex/CriaMultiplosProdutos');
}
catch (Exception e)
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getCause() + ' ' + e.getMessage() + ', Line: ' + e.getLineNumber()));
}
return null;
}
}