2

For a sandbox which has been upgraded with Spring 17 release, I am getting error (screenshot of the error message is mentioned below) from a Visualforce page which is embedded in the standard page layout of a custom object when I am using Google Chrome. It is working fine on Internet explorer.

Error message:

TypeError: Cannot read property 'RIMS_Service_Request_Id__c' of undefined

But I am not getting any error for the same Visualforce page for the sandbox which is still running on Winter 16 release. Please note that I am using Google Chrome for this sandbox too.

The Apex code and Static resource which is being used in Visualforce page is exactly same in both the sandboxes, but I am getting error from one sandbox (upgraded with Spring 17 release) and the other one (still running on Winter 16 release) is working fine which leads me to the conclusion that the root cause of the issue may be Spring 17 release. I would really appreciate any kind of suggestion or solution for this problem.

Below is my Visualforce page coding:

<apex:page standardController="Underwriting__c" extensions="RimsSalesforceConnectCtrl">

    <html>
    <head>
        <title>Rims for Salesforce</title>
    </head>
    <body ng-app="rimsSalesforceConnect" id="RimsSalesforceConnect">

        <md-toolbar>
            <div class="md-toolbar-tools">
                <img src="https://www.everbank.com/~/media/_img/logos/everbank.png" />
            </div>
        </md-toolbar>

        <md-subheader class="md-background md-hue-2">Rims Salesforce Connect</md-subheader>

        <ui-view></ui-view>

        <!-- Constants -->
        <script>
            var constants = {
                userId      : '{!$User.Id}',
                rimsBaseUrl : '{!rimsBaseUrl}'
            }
        </script>

        <!-- Angular JS 1.x -->
        <script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.1/angular.js" type="text/javascript"></script>

        <!-- Angular JS 1.x Dependencies -->
        <script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.3.1/angular-ui-router.js" type="text/javascript"></script>
        <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.min.js" type="text/javascript"></script>
        <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-animate.min.js" type="text/javascript"></script>
        <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-aria.min.js" type="text/javascript"></script>
        <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-messages.min.js" type="text/javascript"></script>
        <script src="//ajax.googleapis.com/ajax/libs/angular_material/1.1.0-rc2/angular-material.min.js" type="text/javascript"></script>
        <script src="//cdnjs.cloudflare.com/ajax/libs/angular-sanitize/1.5.7/angular-sanitize.min.js" type="text/javascript"></script>

        <!-- SPA -->
        <script src="{!URLFOR($Resource.RimsSalesforceConnect, '/package/app/app.js')}" type="text/javascript"></script>
        <script src="{!URLFOR($Resource.RimsSalesforceConnect, '/package/app/factories/dataFactory.js')}" type="text/javascript"></script>
        <script src="{!URLFOR($Resource.RimsSalesforceConnect, '/package/app/factories/utilitiesFactory.js')}" type="text/javascript"></script>
        <script src="{!URLFOR($Resource.RimsSalesforceConnect, '/package/app/services/mapsService.js')}" type="text/javascript"></script>
        <script src="{!URLFOR($Resource.RimsSalesforceConnect, '/package/app/controllers/newFormCtrl.js')}" type="text/javascript"></script>
        <script src="{!URLFOR($Resource.RimsSalesforceConnect, '/package/app/controllers/performPrecheckCtrl.js')}" type="text/javascript"></script>
        <script src="{!URLFOR($Resource.RimsSalesforceConnect, '/package/app/controllers/serviceRequestExistsCtrl.js')}" type="text/javascript"></script>

        <!-- Angular JS 1.x Styles -->
        <link href="//ajax.googleapis.com/ajax/libs/angular_material/1.1.0-rc2/angular-material.min.css" type="text/css" rel="stylesheet" />
        <link href="//fonts.googleapis.com/icon?family=Material+Icons" type="text/css" rel="stylesheet" />
        <link href="{!URLFOR($Resource.RimsSalesforceConnect, '/package/assets/css/index.css')}" type="text/css" rel="stylesheet" />

    </body>
    </html>

</apex:page>

Below is the APEX Class:

global class RimsSalesforceConnectCtrl{ 
    public String rimsBaseUrl { get; set; }
    private static String rimsUsername      = 'username';
    private static String rimsSecretToken   = 'XXXXXXXXXXXXXXXXXXXXXXX';

    global class Wrapper {
        public Boolean success { get; set; }
        public Object messages { get; set; }
        public Object responseBody { get; set; }
    }

    global static String getSobjectFields (String qSobject){

        SObjectType sObjectDescribed = Schema.getGlobalDescribe().get(qSobject);

        Map<String, Schema.SObjectField> objectFields = sObjectDescribed.getDescribe().fields.getMap();

        List<String> fields = new List<String>(objectFields.keySet());

        return String.join(fields, ', ');

    }

    @RemoteAction
    global static Wrapper callout (string endpoint, string method, string data){

        Wrapper w = new Wrapper();

        try{

            Http http = new Http();
            HttpRequest req = new HttpRequest();
            HTTPResponse res = new HTTPResponse();

            req.setHeader('Authorization-UserName', rimsUsername);
            req.setHeader('Authorization-Token', rimsSecretToken);          

            req.setHeader('Content-Type', 'application/json');
            req.setHeader('accept','application/json');
            req.setTimeout(100000);

            req.setEndpoint(endpoint);
            req.setMethod(method);

            if(method == 'POST'){       
                req.setBody(data);
            }

            res = http.send(req);

            JSONParser parser = JSON.createParser(res.getBody());


            w.success = true;
            w.messages = new List<Object>{'Callout to ' + endpoint + ' was completed successfully.'};
            w.responseBody = (Map<String, Object>)JSON.deserializeUntyped(res.getBody());

        }catch(Exception e){

            w.success = false;
            w.messages = new List<Object>{e.getMessage()}; 
        }   

        return w;

    }

    @RemoteAction
    global static Wrapper updateRecord (string currentRecord, string currentUser, string rimsId){

        Wrapper w = new Wrapper();

        try{

            Datetime d = Datetime.now();

            Underwriting__c cp = [SELECT Id, RIMS_Service_Request_ID__c, RIMS_Service_Request_Submitted_By__c, RIMS_Service_Request_Submitted_Date__c FROM Underwriting__c WHERE Id = :currentRecord];
            cp.RIMS_Service_Request_ID__c = rimsId;
            cp.RIMS_Service_Request_Submitted_By__c = currentUser;          
            cp.RIMS_Service_Request_Submitted_Date__c = d;

            UPDATE cp;          
            w.success = true;
            w.messages = new List<Object>{'RIMS Salesforce fields have been updated successfully'};
            w.responseBody = cp;

        }catch(Exception e){

            w.success = false;
            w.messages = new List<Object>{e.getMessage()};
        }       

        return w;

    }

    @RemoteAction
    global static Wrapper dynamicSobjectQuery (String qSobject, String qPredicate, String qParam){

        Wrapper w = new Wrapper();
        String query='';

        try{

            string struser='User';
            if(!qSobject.equals(struser))
               query = 'SELECT ' + getSobjectFields(qSobject) + ' FROM ' + qSobject + ' WHERE ' + qPredicate + ' = \'' + qParam + '\'';
            else
               query = 'SELECT id, username, lastname, firstname, name FROM User WHERE Id'+' = \'' + qParam + '\'';

            List<sObject> results = new List<sObject>(Database.query(query));   

            w.success = true;
            w.messages = new List<Object>{'sObject was retrieved successfully and result set includes all fields.'};
            w.responseBody = results;

        }catch(Exception e){

            w.success = false;
            w.messages = new List<Object>{e.getMessage()};

        }

        return w;

    }

    public RimsSalesforceConnectCtrl (ApexPages.StandardController ctrl){
        rimsBaseUrl = 'https://xyzbank.abcefg.com';

    }

}

Below is the JS code which is referencing RIMS_Service_Request_ID__c which is working fine for Winter 16 salesforce release but throwing error for Spring 17:

var app = angular.module('rimsSalesforceConnect', ['ngMaterial', 'ngSanitize', 'ui.router'])

app.constant('userId', constants.userId)
app.constant('rimsBaseUrl', constants.rimsBaseUrl)
app.constant('resourceUrl', '/resource/' + Date.now() + '/RimsSalesforceConnect/package')
app.constant('rimsExactBidLogo', '/resource/' + Date.now() + '/RimsSalesforceConnect/package/assets/images/RIMSExactBidLogo.jpg')
app.constant('recordId', (function(){
var url = ((window.location != window.parent.location) ? document.referrer : document.location)
return url.substring(url.lastIndexOf('/') + 1, (url.lastIndexOf('?') > -1) ? url.lastIndexOf('?') : url.length)
})())

app.config(['$stateProvider', '$mdDialogProvider', 'resourceUrl', '$mdThemingProvider', function($stateProvider, $mdDialogProvider, resourceUrl, $mdThemingProvider){

$stateProvider
    .state('performPrecheck', {
        templateUrl: resourceUrl + '/app/views/partials/perform-precheck.html',
        controller: 'PerformPrecheckCtrl'
    })
    .state('newForm', {
        templateUrl: resourceUrl + '/app/views/partials/new-form.html',
        controller: 'NewFormCtrl'           
    })
    .state('serviceRequestExists',{
        templateUrl: resourceUrl + '/app/views/partials/service-request-exists.html',
        controller: 'ServiceRequestExistsCtrl'
    })

$mdDialogProvider.addPreset('errors', {
    options: function(){
        return {
            controller: function($scope, $mdDialog, locals){
                $scope.dialog = locals
                $scope.closeDialog = function(){
                    $mdDialog.hide()
                }               
            },
            clickOutsideToClose: false,
            autoWrap: false,
            parent: angular.element(document.querySelector('#RimsSalesforceConnect')),
            templateUrl: resourceUrl + '/app/views/dialogs/errors.html'
        }
    }
})

$mdDialogProvider.addPreset('info', {
    options: function(){
        return {
            controller: function($scope, $mdDialog, locals){
                $scope.dialog = locals
                $scope.closeDialog = function(){
                    $mdDialog.hide()
                }               
            },
            clickOutsideToClose: false,
            autoWrap: false,
            parent:  angular.element(document.querySelector('#RimsSalesforceConnect')),
            templateUrl: resourceUrl + '/app/views/dialogs/info.html'
        }
    }
})

$mdDialogProvider.addPreset('loading', {
    options: function(){
        return {
            clickOutsideToClose: false,
            autoWrap: false,
            parent: angular.element(document.querySelector('#RimsSalesforceConnect')),
            templateUrl: resourceUrl + '/app/views/dialogs/loading.html'
        }
    }
})

$mdThemingProvider.definePalette('primary', {
    '50': '#858585',
    '100': '#5e5e5e',
    '200': '#424242',
    '300': '#1f1f1f',
    '400': '#0f0f0f',
    '500': '#000000',
    '600': '#000000',
    '700': '#000000',
    '800': '#000000',
    '900': '#000000',
    'A100': '#858585',
    'A200': '#5e5e5e',
    'A400': '#0f0f0f',
    'A700': '#000000',
    'contrastDefaultColor': 'light',
    'contrastDarkColors': '50 A100'
});

$mdThemingProvider.definePalette('accent', {
    '50': '#ffffff',
    '100': '#d9f1f2',
    '200': '#aee2e4',
    '300': '#79cfd2',
    '400': '#62c7cb',
    '500': '#4bbfc3',
    '600': '#3cb0b4',
    '700': '#34999d',
    '800': '#2d8386',
    '900': '#256c6f',
    'A100': '#ffffff',
    'A200': '#d9f1f2',
    'A400': '#62c7cb',
    'A700': '#34999d',
    'contrastDefaultColor': 'light',
    'contrastDarkColors': '50 100 200 300 400 500 600 A100 A200 A400'
});

$mdThemingProvider.definePalette('warn', {
    '50': '#ffffff',
    '100': '#fce1dd',
    '200': '#f8b2a9',
    '300': '#f37767',
    '400': '#f15d4a',
    '500': '#ef442e',
    '600': '#ec2b12',
    '700': '#d02610',
    '800': '#b3210e',
    '900': '#971b0c',
    'A100': '#ffffff',
    'A200': '#fce1dd',
    'A400': '#f15d4a',
    'A700': '#d02610',
    'contrastDefaultColor': 'light',
    'contrastDarkColors': '50 100 200 300 400 A100 A200 A400'
});

$mdThemingProvider.theme('default')
    .primaryPalette('primary')
    .accentPalette('accent')
    .warnPalette('warn')

}])

app.run(['$state', '$timeout', 'dataFactory', 'recordId', '$mdDialog',    function($state, $timeout, dataFactory, recordId, $mdDialog){

$timeout(function(){

    dataFactory.dynamicSobjectQuery('Underwriting__c', 'Id', recordId)
    .then(function(d){

        if(d.success){

            if(d.responseBody[0].RIMS_Service_Request_ID__c) {
                $state.go('serviceRequestExists')
            }else{
                $state.go('performPrecheck')
            }

        }else{  

            var dialog = {}
            dialog.header = 'Something went wrong'
            dialog.content = [d.messages]       

            $mdDialog.show( $mdDialog.info( { locals: dialog } ) ) 

        }

    })
    .catch(function(err){

        var dialog = {}
        dialog.header = 'Something went wrong'
        dialog.content = [String(err), 'Please refresh the page.']  

        $mdDialog.show( $mdDialog.info( { locals: dialog } ) )  

    })

})

}])
  • 2
    In the future, please edit your existing post instead of asking a new one. salesforce.stackexchange.com/questions/156544/… And while it's great that you've shared your code with us, it looks like the only code we actually need to see is Resource.RimsSalesforceConnect, which you didn't share here. – Adrian Larson Jan 20 '17 at 17:28
  • This seems to be a JavaScript error coming from one of your included scripts. Try to search for the places where you are fetching RIMS_Service_Request_ID__c field value from any JS variable, that variable is not getting initialized due to some reason. – Santanu Halder Jan 20 '17 at 17:32
  • Er...yeah didn't realize that's a zipped package. One or more of your .js files should contain a reference to that field. You're going to have to use basic investigation skills to get to the file that is causing the issue. Once you do that and share it here, we can probably help. – Adrian Larson Jan 20 '17 at 17:43
  • Hi Adrian, I have updated my query to include the JS code. Please let me know what I am doing wrong in that code. – Sandip SFDC Jan 20 '17 at 18:15
  • Your dataFactory.dynamicSobjectQuery method is returning undefined. – Adrian Larson Jan 20 '17 at 22:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.