• Michael Mongeau
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
I have a test function with seeAllData=true declared.  It creates an opportunity, queries the PricebookEntry object for a specific record, and then creates an opportunity line referencing that pricebook entry.
The first two System.debug statements return a record ID for the PricebookEntry and related Product2 entry.   When the PricebookEntry ID is assigned to an opportunity line item and then referenced as oli.PricebookEntry.Product2Id the value is 'null'.  What is going on here, where the SOQL query result shows a value but assigning it to a line causes it to be null?
 
@isTest(seeAllData=true)
    public static void integrationTest(){
        Account testAccount = TestUtil.createAccount();
        Opportunity o = TestUtil.createOpportunity(testAccount.Id);
        String currencyCode = [select CurrencyIsoCode from Opportunity where Id = :o.Id].CurrencyIsoCode;
        PricebookEntry pe1 = [select Id,Product2Id 
                              from PricebookEntry 
                              where IsActive = true 
                              and Pricebook2.IsStandard = true 
                              and CurrencyIsoCode = :currencyCode 
                              limit 1];
        System.debug('>>> pe1.Id = ' + pe1.Id);
        System.debug('>>> pe1.Product2Id = ' + pe1.Product2Id);
        OpportunityLineItem oli1 = new OpportunityLineItem(
            OpportunityId = o.Id,
            Quantity = 1,
            UnitPrice = 1,
            Configurator_Timestamp__c = Datetime.now()
        );
        oli1.PricebookEntryId = pe1.Id;
        System.debug('>>> oli1.PricebookEntryId = ' + oli1.PricebookEntryId);
        System.debug('>>> oli1.PricebookEntry.Product2Id = ' + oli1.PricebookEntry.Product2Id);
Debug output.

debug output
I have a test function with seeAllData=true declared.  It creates an opportunity, queries the PricebookEntry object for a specific record, and then creates an opportunity line referencing that pricebook entry.
The first two System.debug statements return a record ID for the PricebookEntry and related Product2 entry.   When the PricebookEntry ID is assigned to an opportunity line item and then referenced as oli.PricebookEntry.Product2Id the value is 'null'.  What is going on here, where the SOQL query result shows a value but assigning it to a line causes it to be null?
 
@isTest(seeAllData=true)
    public static void integrationTest(){
        Account testAccount = TestUtil.createAccount();
        Opportunity o = TestUtil.createOpportunity(testAccount.Id);
        String currencyCode = [select CurrencyIsoCode from Opportunity where Id = :o.Id].CurrencyIsoCode;
        PricebookEntry pe1 = [select Id,Product2Id 
                              from PricebookEntry 
                              where IsActive = true 
                              and Pricebook2.IsStandard = true 
                              and CurrencyIsoCode = :currencyCode 
                              limit 1];
        System.debug('>>> pe1.Id = ' + pe1.Id);
        System.debug('>>> pe1.Product2Id = ' + pe1.Product2Id);
        OpportunityLineItem oli1 = new OpportunityLineItem(
            OpportunityId = o.Id,
            Quantity = 1,
            UnitPrice = 1,
            Configurator_Timestamp__c = Datetime.now()
        );
        oli1.PricebookEntryId = pe1.Id;
        System.debug('>>> oli1.PricebookEntryId = ' + oli1.PricebookEntryId);
        System.debug('>>> oli1.PricebookEntry.Product2Id = ' + oli1.PricebookEntry.Product2Id);
Debug output.

debug output
I keep getting this error for the below challenge:

Error: Challenge Not yet complete... here's what's wrong: 
The 'Phone__x' external object is not correctly setup with an indirect relationship to the User standard object.

The mobile phones being tracked by an external application are used by specific users in your Salesforce instance. Create an indirect lookup relationship between the 'Phone' External Object and the 'User' standard object.
  • Create an OData 2.0 external data source with 'Mobile Devices' as the label, 'Mobile_Devices' as the name, and this URL: https://phone-odata-demo.herokuapp.com/devices.svc/. Note: If you have completed the previous challenge in this module ('Setting up Lightning Connect'), the External Data Source should already exist in your Developer Edition.
  • Add a new 'Phone UUID' custom field on the User standard object with the resulting API name of 'Phone_UUID__c'. The field should be of type 'Text' and marked as 'Unique' and 'External ID'.
  • Change the 'UUID' field on the 'Phone__x' external object to be an indirect lookup relationship to the 'User' standard object. Use the 'Phone_UUID__c' field as the matching key for this indirect lookup relationship.
  • Update any existing User record in your Developer Edition instance to have a value of '0000123442' for the 'Phone_UUID__c' field.
This is a screenshot of the custom user field:

User-added image

Here is the UUID field:
User-added image


What am I doing wrong?