• Fei Yang
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
Ie created some Apex classes in sandbox and tested them with Developer Console.

As in screen below, clicking on the class name at top left should open a test log window. Everything was ok, but not from this week. We can see the clicking prompts an error window instead of the log window.

Can anyone help this?
User-added image
I'm a greener of Apex development.

I'm now creating a Trigger Test Class. The class is to create a new Account, and then create a Opportunity for the Account.

My problem is, after creating Account and Opportunity, I could not get Account by soql query. Can anyone help this?

My code and Execution log as below:

@isTest
public with sharing class TriggerTest_InvoiceItemUpdate {
    static testMethod void myUnitTest()
    {
        test.startTest();
            List<Account> accounts = new List<Account>{};
            List<Opportunity> opportunities = new List<Opportunity>{};
            String AccountId, OpportunityID;
       
         //Create a new Account
            Account testAccount = new Account(Name='Account_Test');
            accounts.add(testAccount);
            insert accounts; 
            AccountId = accounts[0].id;
       
         //Create a new Opportunity
            Opportunity Opportunity_test= new Opportunity(Account = accounts[0], Name='Opportunity_Test', StageName='Close Won', CloseDate=date.newInstance(2011, 7, 4));
            opportunities.add(Opportunity_test);
            insert opportunities;
            OpportunityID=opportunities[0].id;
            system.debug('1>>>'+opportunities[0].Account.id);
        
         //To querry the Opportunity's Account
         opportunities =[select id, account.name  from Opportunity where id=: OpportunityID];
         system.debug('2>>>'+opportunities[0]);
         system.debug('3>>>'+opportunities[0].account.name);
       
        test.stopTest();
        }
}



Execution log:
[21]|DEBUG|1>>>001N000000ACdfjIAD
[25]|DEBUG|2>>>Opportunity:{Id=006N0000003BzKOIA0}
[26]|DEBUG|3>>>null
I'm a greener of Apex development.

I'm now creating a Trigger Test Class. The class is to create a new Account, and then create a Opportunity for the Account.

My problem is, after creating Account and Opportunity, I could not get Account by soql query. Can anyone help this?

My code and Execution log as below:

@isTest
public with sharing class TriggerTest_InvoiceItemUpdate {
    static testMethod void myUnitTest()
    {
        test.startTest();
            List<Account> accounts = new List<Account>{};
            List<Opportunity> opportunities = new List<Opportunity>{};
            String AccountId, OpportunityID;
       
         //Create a new Account
            Account testAccount = new Account(Name='Account_Test');
            accounts.add(testAccount);
            insert accounts; 
            AccountId = accounts[0].id;
       
         //Create a new Opportunity
            Opportunity Opportunity_test= new Opportunity(Account = accounts[0], Name='Opportunity_Test', StageName='Close Won', CloseDate=date.newInstance(2011, 7, 4));
            opportunities.add(Opportunity_test);
            insert opportunities;
            OpportunityID=opportunities[0].id;
            system.debug('1>>>'+opportunities[0].Account.id);
        
         //To querry the Opportunity's Account
         opportunities =[select id, account.name  from Opportunity where id=: OpportunityID];
         system.debug('2>>>'+opportunities[0]);
         system.debug('3>>>'+opportunities[0].account.name);
       
        test.stopTest();
        }
}



Execution log:
[21]|DEBUG|1>>>001N000000ACdfjIAD
[25]|DEBUG|2>>>Opportunity:{Id=006N0000003BzKOIA0}
[26]|DEBUG|3>>>null