The Welkin Suite Forum

Salesforce Winter 18 - Compiler Change - Required Namespaces



Salesforce Winter 18 - Compiler Change - Required Namespaces

  • Please log in to reply

#1
windows version welkinsuite

mlochiano

    Posted 14 Jul 2017

    We just received a notification from Salesforce that they are going to make mandatory changes to their Apex compiler.   One of these changes will be incredibly disruptive to our development.   We have over 200,000 lines of code in over 700 classes.   Below is the notification.   It implies that we will have to locate every table (and perhaps field) reference in our code and decide if it needs to be prepended with a "schema.' reference for safety.

      This is in direct conflict with the current development guidence from Salesforce that these namespaces will be 'implicit'.

      This will take many, many man-months of effort to review and update code and also require us to retest every class.   It appears that Salesforce just does not care.

      Is there anyway that Welkin can develp an automated approach to this incredibly stuipd requirement.

    BEHAVIOR 6:
    "Account" type binds to "Schema.Account" when namespace is null or empty
    The compiler is not correctly requiring the use of the Schema namespace when there is a user-defined type with the same name. For example, in the following code, the type Contact should be specified to be in the Schema namespace if there is also a Contact class in the same implicit namespace:
    public map<String, Contact> getContacts(List<String> mails){
    return getContactsByMap([SELECT Id, Email FROM Contact WHERE Email IN :mails]);
    }

    It's possible that your code is not behaving the way you expect because it may be binding to a different type than the one you intended. In other words, if you have shadowed a standard SObject type with an apex class of the same name, this change will cause your custom class to take precedence over the standard SObject type, unless the Schema namespace is explicitly specified.

    Suggested fix

    We suggest fixing the code by prepending the correct namespace to types in the Schema namespace if a name collision with a user-defined type is possible, and you intend to bind to the Schema SObject type.
    public map<String, Schema.Contact> getContacts(List<String> mails){
    return getContactsByMap([SELECT Id, Email FROM Contact WHERE Email IN :mails ]);
    }



    0 replies to this topic



    Boost Your Productivity. Get Started Today

    Try Free Trial