You need to sign in to do that
Don't have an account?
j_id0:j_id2:pb:j_id4:j_id5:j_id7: An error occurred when processing your submitted information.
I am getting the above error when trying to call the save action on the following
Apex Page:
<apex:page tabStyle="Service_Product__c" controller="AddServiceStandardPriceController">
<apex:messages />
<apex:form >
<apex:pageblock id="pb" title="Add Standard Price" mode="Edit">
<apex:outputLabel value="{!serviceName}"/>
<apex:pageBlockSection >
<apex:pageblocksectionItem >
<apex:outputlabel value="Standard Price"/>
<apex:inputText value="{!StandardPrice}"/>
</apex:pageblocksectionItem>
<apex:pageblocksectionItem >
<apex:outputlabel value="IsActive"/>
<apex:inputCheckbox value="{!IsActive}"/>
</apex:pageblocksectionItem>
</apex:pageBlockSection>
<apex:commandButton value="Save"/>
<apex:commandButton value="Cancel"/>
</apex:pageblock>
</apex:form>
</apex:page>
controller:
public class AddServiceStandardPriceController
{
public string serviceProdId;
public Decimal StandardPrice;
public Service_PricebookEntry__c ServicePriceBookRecord;
public Boolean IsActive;
public AddServiceStandardPriceController()
{
serviceProdId = ApexPages.currentPage().getParameters().get('id');
}
//getter and setter for standard price
public Decimal getStandardPrice()
{
Decimal priceBookEntryUnitPrice;
List<String> recordId = new List<String>();
recordId.Add(serviceProdId);
//get the Pricebook entry on the standard price book for the service product
Service_PricebookEntry__c[] serPriceBookEnteries = [Select Id,IsActive__c,Service_Pricebook__r.IsStandard__c
,Service_Product__r.Id,Unit_Price__c
from Service_PricebookEntry__c
Where Service_Pricebook__r.IsStandard__c = true And
Service_Product__r.Id In :recordId limit 1];
if(serPriceBookEnteries.size() > 0)
{
ServicePriceBookRecord = serPriceBookEnteries[0];
priceBookEntryUnitPrice = serPriceBookEnteries[0].Unit_Price__c;
}
else
{
priceBookEntryUnitPrice = 0;
}
return priceBookEntryUnitPrice ;
}
public void setStandardPrice(Decimal txtStandardPriceData)
{
StandardPrice = txtStandardPriceData;
}
//getter and setter for IsActive
public Boolean getIsActive()
{
Boolean active;
List<String> recordId = new List<String>();
recordId.Add(serviceProdId);
//get the Pricebook entry on the standard price book for the service product
Service_PricebookEntry__c[] serPriceBookEnteries = [Select Id,IsActive__c,Service_Pricebook__r.IsStandard__c
,Service_Product__r.Id,Unit_Price__c
from Service_PricebookEntry__c
Where Service_Pricebook__r.IsStandard__c = true And
Service_Product__r.Id In :recordId limit 1];
if(serPriceBookEnteries.size() > 0)
{
ServicePriceBookRecord = serPriceBookEnteries[0];
active = serPriceBookEnteries[0].IsActive__c;
}
else
{
active = true;
}
return active ;
}
public void setIsActive(Boolean chkIsActive)
{
IsActive = chkIsActive;
}
public string getServiceName()
{
List<String> servProdIds = new List<String>();
servProdIds.Add(serviceProdId);
Service_Product__c[] serviceProds = [Select Name from Service_Product__c Where Id IN :servProdIds limit 1];
if(serviceProds.size() > 0)
return serviceProds[0].Name;
else
return 'This is not working';
}
public PageReference save()
{
Pagereference p = null;
if(ServicePriceBookRecord != null) //record exists
{
try
{
ServicePriceBookRecord.Unit_Price__c = StandardPrice;
update ServicePricebookRecord;
}
catch(DmlException ex)
{
ApexPages.addMessages(ex);
}
}
else //create new
{
try
{
Service_Pricebook__c[] serPriceBook = [Select Id, IsActive__c, IsStandard__c from Service_Pricebook__c s where IsStandard__c = true limit 1];
List<Service_PricebookEntry__c> serPriceBookEntryRecs = new List<Service_PricebookEntry__c>();
Service_PricebookEntry__c servPriceBookEntryRec = new Service_PricebookEntry__c();
servPriceBookEntryRec.Service_Pricebook__c = serPriceBook[0].Id;
servPriceBookEntryRec.Service_Product__c = serviceProdId;
servPriceBookEntryRec.Unit_Price__c = StandardPrice;
servPriceBookEntryRec.IsActive__c = IsActive;
serPriceBookEntryRecs.Add(servPriceBookEntryRec);
insert servPriceBookEntryRec;
p = Page.Services;
}
catch(DmlException ex)
{
ApexPages.addMessages(ex);
}
}
return p;
}
}
It worked when using Double instead of Decimal for currency.
All Answers
add the id parameter to your apex tags so you can find out which field is having the error. i imagine this is some validation rule configured in your org, and narrowing the tags down will show you what field the rule is on. when you supply an id for your apex tags, you won't get autogenerated ones like "j_id0"
can you check to see whether you have validation rules on this field configured or not? the reason I ask, is that this error message doesnt' sound standard, it sounds like something that I would use, rather than the super helpful SF error messaging like "index out of bound, have a nice day".
/p
i don't work with currency often, but maybe you can do a conversion?
double d = 12.54;
currency c;
c = currency.valueof(d);
(no idea if this works, but thinking that you have to convert your value to currency explicitly before writing to the field)
I think there are several things you should clean up:
1. You have no Actions on your Save or Cancel commandButtons, so all it will do is refresh the page, not actually call your save method.
2. Your getters query and requery the database each time they are called instead of setting up the information the first time and then returning it. Also, both getters are doing the same query. Set up an onLoad action on the apex:page tag and do your query there. Then the getters can just return the result.
3. Your queries set up arrays for the results, and check for the size, and yet there is a Limit 1. Why not clean that up.
4. It's unclear to me why you aren't using inputField and outputField tags. Price is eventually being saved into a Unit_Price__c record, so why not instantiate one of those and use it to gather your information. Same for Active__c which is in a Service_PricebookEntry__c record. That way you maintain a dependency between those fields in the object definition and your use of them in a VF page. You get the labels and validations, etc.
5. Don't just catch DML Exceptions. That's good, but also catch other exceptions.
6. serPriceBookEntryRecs isn't used and should be tossed.
Hope this helps, best, Steve.
Thanks for the clean up advice . I know its a bad habit of mine.
1) I added the save and cancel mehtods but still am gettinf the same error on txtStdfield:
j_id0:j_id2:pb:j_id4:j_id5:txtStdPrice: An error occurred when processing your submitted information.
I believe its in the setter for StandardPrice.The Unit_Price__c field is of type currency in SF but it wont support currency data type in apex so i am using decimal . Its working fine in the getter so i am not sure why its not working for the setter.
2) I guess I will need to set up the StandardController to that Object in order to directly bind the properties to the inputField.I dont want to use one. Instead I just want to use custom controller.
It worked when using Double instead of Decimal for currency.