0

Can anyone substantiate why this is?

    Opportunity o2 = new Opportunity();
    o2.Name = 'DSGTestClassRecord Opportunity 2';
    o2.StageName = 'New';
    o2.CLoseDate = Date.today();
    insert o2;

    Opportunity OppRec1 = [select Id From Opportunity Where Name = 'DSGTestClassRecord Opportunity 2'];
    OppRec1.StageName = 'Closed Won';
    OppRec1.Sub_Stage__c = 'Paid';
    OppRec1.Opportunity_Discount_Approved__c = true;

    update OppRec1;

In this class code, the OppRec1 SELECT statement is returning that no rows are found. What?

1 Answer 1

2

1) instead of using name= 'DSGTestClassRecord Opportunity 2' do Id = : o2.Id;

Opportunity OppRec1 = [select Id From Opportunity Where id=: o2.Id];

2) If you want to verify the name is the one you inserted

System.assertEquals('DSGTestClassRecord Opportunity 2', o2.name);
2
  • Interesting. I had misunderstood that the search (by name) was important to the particular test being done, but it is not. Thanks!
    – AMM
    Dec 12, 2012 at 19:23
  • 1
    I am sure you might have tried looking up, but just incase the reference slipped out,check this doc : wiki.developerforce.com/page/How_to_Write_Good_Unit_Tests
    – Rao
    Dec 12, 2012 at 19:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .