Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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);
share|improve this answer
    
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 '12 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 '12 at 19:36
    
Thank you. . . . –  AMM Dec 12 '12 at 19:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.