• Jordan Lee 13
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies
I have created two classes and a test class to test these classes. The test class creates an Opportunity object and populates a few fields. It continues to pass the id of the opportunity to the class being tested. When a SOQL query is run with the pass Id, none of the other fields included in the SOQL query are being populated.

Here is the test class:
@isTest
public class TestGatewayBalancer {
    @isTest public static void AssignGatewayWithLowestRatio() {
        Opportunity opp = new Opportunity(Name = 'Test', StageName = 'New', CloseDate = Date.Today());
        opp.ChargentSFA__Charge_amount__c = 100;
        Database.insert(opp);
    System.debug(loggingLevel.ERROR, '=> Opp being passed from test to upfront class: ' + opp);

        Test.StartTest();
        UpfrontGatewayBalancer.manualCharge(opp.Id);
        Test.StopTest();

        System.assertEquals(gateway.Id, opp.ChargentSFA__Gateway__c, 'The gateway is incorrect.');
    }

The class that is being tested:
global with sharing class UpfrontGatewayBalancer {
    webService static Boolean manualCharge(Id oppID) {
        Opportunity opp = [SELECT Id, ChargentSFA__Gateway__c, ChargentSFA__Charge_Amount__c FROM Opportunity WHERE Id = :oppID];
        //Find and assign appropriate gateway
        System.debug(loggingLevel.ERROR, '=> Opp being passed from upfront to the handler class: ' + opp);
        GatewayLoadBalancerUtility.OpportunityHandler(opp);
        //Check if gateway was assigned before returning
        if(opp.ChargentSFA__Gateway__c == null) {
            return false;
        }
        else {
            return true;
        }
    }

And the messages I get in the execution log are the following:
13:10:25:909 USER_DEBUG [26]|ERROR|=> Opp being passed from test to upfront class: Opportunity:{Name=Test, StageName=New, CloseDate=2016-11-14 00:00:00, ChargentSFA__Charge_Amount__c=100, Id=00655000007bmnWAAQ}

13:10:26:005 USER_DEBUG [14]|ERROR|=> Opp being passed from upfront to the handler class: Opportunity:{Id=00655000007bmnWAAQ}

So clearly the object has those fields getting set in the test class, but they aren't pulled down from the SOQL query in the class being tested. If anybody has any ideas as to what's going on here I would appreciate the help.
 
I have created two classes and a test class to test these classes. The test class creates an Opportunity object and populates a few fields. It continues to pass the id of the opportunity to the class being tested. When a SOQL query is run with the pass Id, none of the other fields included in the SOQL query are being populated.

Here is the test class:
@isTest
public class TestGatewayBalancer {
    @isTest public static void AssignGatewayWithLowestRatio() {
        Opportunity opp = new Opportunity(Name = 'Test', StageName = 'New', CloseDate = Date.Today());
        opp.ChargentSFA__Charge_amount__c = 100;
        Database.insert(opp);
    System.debug(loggingLevel.ERROR, '=> Opp being passed from test to upfront class: ' + opp);

        Test.StartTest();
        UpfrontGatewayBalancer.manualCharge(opp.Id);
        Test.StopTest();

        System.assertEquals(gateway.Id, opp.ChargentSFA__Gateway__c, 'The gateway is incorrect.');
    }

The class that is being tested:
global with sharing class UpfrontGatewayBalancer {
    webService static Boolean manualCharge(Id oppID) {
        Opportunity opp = [SELECT Id, ChargentSFA__Gateway__c, ChargentSFA__Charge_Amount__c FROM Opportunity WHERE Id = :oppID];
        //Find and assign appropriate gateway
        System.debug(loggingLevel.ERROR, '=> Opp being passed from upfront to the handler class: ' + opp);
        GatewayLoadBalancerUtility.OpportunityHandler(opp);
        //Check if gateway was assigned before returning
        if(opp.ChargentSFA__Gateway__c == null) {
            return false;
        }
        else {
            return true;
        }
    }

And the messages I get in the execution log are the following:
13:10:25:909 USER_DEBUG [26]|ERROR|=> Opp being passed from test to upfront class: Opportunity:{Name=Test, StageName=New, CloseDate=2016-11-14 00:00:00, ChargentSFA__Charge_Amount__c=100, Id=00655000007bmnWAAQ}

13:10:26:005 USER_DEBUG [14]|ERROR|=> Opp being passed from upfront to the handler class: Opportunity:{Id=00655000007bmnWAAQ}

So clearly the object has those fields getting set in the test class, but they aren't pulled down from the SOQL query in the class being tested. If anybody has any ideas as to what's going on here I would appreciate the help.