Find your content:

Search form

You are here

Test Class returning error

 
Share

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?


Attribution to: AMM

Possible Suggestion/Solution #1

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);

Attribution to: Rao
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/5352

My Block Status

My Block Content