You need to sign in to do that
Don't have an account?

Error Message: Changed Field: bad value for restricted picklist field: created
Reference message:
I can't display a Histories related list in a VF page. I used Ron Hess's method of using a pageBlock to get the related list items except one, "Field" (i.e. without the last column in the code below, the VF page displays without an error message). The error message in the Subject is what is created when I try and access that field. The WDSL has
<element name="Field" nillable="true" minOccurs="0" type="xsd:string" />
Code:
<apex:pageBlockTable value="{!SCRB_SalesOrder__c.Histories}" var="h"> <apex:column headerValue="Date" value="{!h.createddate}"/> <apex:column headerValue="User" value="{!h.CreatedById}"/> <apex:column headerValue="Action" value="{!h.Field}"/> </apex:pageBlockTable>
The normal View page displays the following after I created the record and then I made a change to the "Status Code" field.
Date | User | Action |
---|---|---|
9/18/2008 7:04 PM | xxxxxxxxxxx | Changed Status Code from Draft to Pre-build. |
9/13/2008 2:22 PM | xxxxxxxxxxx |
Created. |
The VF page generated the following error messages:
After the record was created:
Changed Field: bad value for restricted picklist field: created
Here is another error message on the VF page when "Status Code" field was changed:
Changed Field: bad value for restricted picklist field: StatusCode__c
Thanks for any help.
Here's what we did to work around this problem. Basically we check for the bad value and display our own string if we find it:
<div id="relatedHistory"> <apex:pageBlock title="{!$ObjectType.CaseHistory.labelplural}"> <apex:dataTable styleClass="list" value="{!case.Histories}" var="v_caseHistory"> <!-- SObject row was retrieved via SOQL without querying the requested field: CaseHistory.Field If you get something like this for any other related list for no explainable reason, then go mess with the page layout for the parent object. Add in the OOB related list, or remove it and add it back in, etc, save, and that seems to fix things. --> <apex:column headerValue="{!$ObjectType.CaseHistory.fields.Field.label}"> <!-- Workaround for error: bad value for restricted picklist field: created --> <apex:outputText rendered="{!NOT(v_caseHistory.Field = 'created')}" value="{!v_caseHistory.Field}"/> <apex:outputText rendered="{!v_caseHistory.Field = 'created'}" value="Case Created"/> </apex:column> <apex:column headerValue="{!$ObjectType.CaseHistory.fields.OldValue.label}" value="{!v_caseHistory.OldValue}"/> <apex:column headerValue="{!$ObjectType.CaseHistory.fields.NewValue.label}" value="{!v_caseHistory.NewValue}"/> <apex:column headerValue="{!$ObjectType.CaseHistory.fields.CreatedDate.label}" value="{!v_caseHistory.CreatedDate}"/> <apex:column headerValue="{!$ObjectType.CaseHistory.fields.CreatedById.label}" value="{!v_caseHistory.CreatedById}"/> </apex:dataTable> </apex:pageBlock> </div>
All Answers
then you can present it on the visualforce page easily.
to cast this from AnyType to String in Apex code , you will need a wrapper object around histories related list.
sounds harder than it is, here is code to do this on a case object, you can adapt this:
http://wiki.apexdevnet.com/index.php/Visualforce_CaseHistoryTimeline
i suggest installing this sample, get it running then adapt it for your custom object.
Here's what we did to work around this problem. Basically we check for the bad value and display our own string if we find it:
<div id="relatedHistory"> <apex:pageBlock title="{!$ObjectType.CaseHistory.labelplural}"> <apex:dataTable styleClass="list" value="{!case.Histories}" var="v_caseHistory"> <!-- SObject row was retrieved via SOQL without querying the requested field: CaseHistory.Field If you get something like this for any other related list for no explainable reason, then go mess with the page layout for the parent object. Add in the OOB related list, or remove it and add it back in, etc, save, and that seems to fix things. --> <apex:column headerValue="{!$ObjectType.CaseHistory.fields.Field.label}"> <!-- Workaround for error: bad value for restricted picklist field: created --> <apex:outputText rendered="{!NOT(v_caseHistory.Field = 'created')}" value="{!v_caseHistory.Field}"/> <apex:outputText rendered="{!v_caseHistory.Field = 'created'}" value="Case Created"/> </apex:column> <apex:column headerValue="{!$ObjectType.CaseHistory.fields.OldValue.label}" value="{!v_caseHistory.OldValue}"/> <apex:column headerValue="{!$ObjectType.CaseHistory.fields.NewValue.label}" value="{!v_caseHistory.NewValue}"/> <apex:column headerValue="{!$ObjectType.CaseHistory.fields.CreatedDate.label}" value="{!v_caseHistory.CreatedDate}"/> <apex:column headerValue="{!$ObjectType.CaseHistory.fields.CreatedById.label}" value="{!v_caseHistory.CreatedById}"/> </apex:dataTable> </apex:pageBlock> </div>
How did you write the unit tests for this solution?
Updating an Opportunity within a unit test does not generated any OpportunityFieldHistory records, so your test code has to create them explicitly.
But the fields OldValue and NewValue are not writeable, so they can't be set as part of your test data. It seems they can never be anything other than null in a test class.
How did you overcome this issue?
The best you can do here is move the logic that checks for the values from visual force to the back end (Apex) and unit test that way