+ Start a Discussion
PlainviewPlainview 

Correct syntax for new field on VisualForce Page.

Hello,

I'm attempting to add a new field to a VisualForce page but I am receiving this Error Message:

System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Contract.X18_Digit_Account_Id__c

X18_Digit_Account_Id__c is a custom field on the contract object.

Here's where I'm trying to add it  (in bold):

<apex:pageBlockSectionItem >
    <apex:outputLabel value="Demo ID" for="DemoIDNumber"/>
    <apex:outputText value="{!DemoIDNumber}" id="DemoIDNumber"/>   
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem >
    <apex:outputLabel value="Account ID" for="BOAccountID"/>
    <apex:outputText value="{!contract.BO_Account__c}" id="BOAccountID"/>
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem >
    <apex:outputLabel value="18 Digit Account ID" for="X18_Digit_Account_Id__c"/>
    <apex:outputText value="{!contract.X18_Digit_Account_Id__c}" id="X18_Digit_Account_Id__c"/>
</apex:pageBlockSectionItem>


<apex:pageBlockSectionItem >
    <apex:outputLabel value="Creator ID" for="BO_User_ID__c"/>
    <apex:outputText value="{!user.BO_User_ID__c} ({!user.Name})" id="BO_User_ID__c"/>

</apex:pageBlockSectionItem>
       
<apex:pageBlockSectionItem >
    <apex:outputLabel value="Account Name" for="contractAccountName"/>
    <apex:outputText value="{!contract.Account.Name}" id="contractAccountName"/>
</apex:pageBlockSectionItem>

I've also attached a screenshot of how the page looks before my change.

I'm a new Developer - can anyone help me sort out the syntax? This is my first alteration to a VF page. I've searched for this error message and have reviewed the resulting posts but am having difficulty applying the info. to my situation.

Thanks,
Julien

User-added image

Best Answer chosen by Plainview
Denis VakulishinDenis Vakulishin
Hi,
I think you should add X18_Digit_Account_Id__c field in your controller. Do you have custom controller for this page or just use standard ?(check apex:page element)

All Answers

Denis VakulishinDenis Vakulishin
Hi,
I think you should add X18_Digit_Account_Id__c field in your controller. Do you have custom controller for this page or just use standard ?(check apex:page element)

This was selected as the best answer
PlainviewPlainview
Hi Denis,

Thanks for your response. We do have an Apex Class that the page refers to. Here's the first line from the VF Page:

<apex:page controller="ProvisioningInfo"

Is that what you mean?


Denis VakulishinDenis Vakulishin
Yep, thanks.
So you need to find piece of code with SOQL in ProvisioningInfo controller where your  contract is queried and add X18_Digit_Account_Id__c field there.
Or if you can past ProvisioningInfo's code here and I'll try to help you more.


PlainviewPlainview
Thanks again, Denis! Here's the ProvisioningInfo code (it's very long). Needle in a haystack for me, so I really appreciate the help! Here's a Github secret gist link for you (too much code to paste here):

https://gist.github.com/jcamp6/f5888f0764f9c7d4fa26




Denis VakulishinDenis Vakulishin
Your SOQL is at line #225.
Just add X18_Digit_Account_Id__c field there and check.
PlainviewPlainview
Ugh: Error: ProvisioningInfo Compile Error: only aggregate expressions use field aliasing at line 225 column 25
PlainviewPlainview
contractList =  [SELECT
                        Id,
                        Account.Name,
                        X18_Digit_Account_Id__c
                        Account.Phone,
                        Allow_Share__c,
                        Pricing_Type__c,
Denis VakulishinDenis Vakulishin
You forgot to add comma after X18_Digit_Account_Id__c
contractList =  [SELECT
                        Id,
                        Account.Name,
                        X18_Digit_Account_Id__c,
                        Account.Phone,
                        Allow_Share__c,
                        Pricing_Type__c,
PlainviewPlainview
OH, duh.

PlainviewPlainview
And more ...

Error: ProvisioningInfo Compile Error: Test methods must be in test classes at line 860 column 28.

I'm looking, too.
Denis VakulishinDenis Vakulishin
It's because you updated class API version. The best solution is to move "static testMethod void doTest()  " line #859 to new test class, or just for now you can comment it, but you should move it before deploying to PROD Org.
PlainviewPlainview
Hmmmm. Sorry, I am a bit lost. So, are you saying to move lines 860-on to a separate test class? Just to be sure - I create a new test class and remove this section from this code and paste it into the new class? As I said, new Developer here ... thanks for your patience.
Denis VakulishinDenis Vakulishin
Yes, you should move whole doTest() method to your new class. It will cause no harm to your logic.
PlainviewPlainview
Denis - thanks, you've been a huge help. Will be hard to choose which is your best answer!

The VF Page is now working (once I removed lines 860 - on (the test code) and the field is there. I attempted to create a new Apex Class for the test but hit a wall there but I can work with someone internally to get that resolved and not take up anymore of your time.

Thanks again!!

Best,
Julien