+ Start a Discussion
Patrick Mayer 4Patrick Mayer 4 

Standard Controller addFields works fine in sandbox, fails in production

public with sharing class OrdersPageControllerExtension {
    public ApexPages.StandardController sc;
    public final Order__c order;

    public OrdersPageControllerExtension(ApexPages.StandardController stdController) {
        this.sc = stdController;
        if (!Test.isRunningTest()) { 
            stdController.addFields(new List<String>{'Products__c', 'Restaurant_ID__c', 'Gift_Card__c'});
        }
        if (order.Products__c != null) {
            .....
        }
    }
}


System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Order__c.Products__c 

Has anyone else seen this? Is it a bug?

Best Answer chosen by Patrick Mayer 4
Patrick Mayer 4Patrick Mayer 4
It turns out when my code got deployed I had forgotten to deploy the profiles and I did not have permission to the Products__c field.

All Answers

Davide MolinariDavide Molinari
Hi Patrick,
Does field exist also in prod env?

Davide
Patrick Mayer 4Patrick Mayer 4
Yup, all fields are in Production as well.
Davide MolinariDavide Molinari
Hi Patrick,
I didn't understand why in Sandbox is working, for what I read: execute 'system.debug' of 'order' obj can help understand if it is instantiated or not.
You can also make a query to retrieve the order...
Patrick Mayer 4Patrick Mayer 4
It turns out when my code got deployed I had forgotten to deploy the profiles and I did not have permission to the Products__c field.
This was selected as the best answer
Jason MarshallJason Marshall
Cool that helped me out to, thanks.