function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kumar.fdc81.3902978579608325E12kumar.fdc81.3902978579608325E12 

System.QueryException: List has no rows for assignment to SObject

Hi all,

Test class error on this line
OpportunityPipeline_Change__c pc = [select Stage_After__c from pportunityPipeline_Change__c where Opportunity__c = :O.Id];
I tried using list and limit.

Thanks
kumar
Vinit_KumarVinit_Kumar
Isn't the error self explanatory that you don't have any record to associated to pportunityPipeline_Change__c with Oppotuntiy.

Can you post the whole code as how you are doing it,I am assuming that you are not associating pportunityPipeline_Change__c record with correct Opportunity record.

kumar.fdc81.3902978579608325E12kumar.fdc81.3902978579608325E12
HI Vinit,

@isTest
private class OpportunityPipelineChangeTest { 
     static testMethod void myUnitTest() {
//COMMENT: First, prepare Dummy Opportunity
        Account a = new Account(Name='OpportunityPipelineChangeTest',Geography__c='TestGeography',Territory_Id__c='TestTerritory',
            Territory_Overlay__c='TestTerritoryOverlay',Renewals_Team__c='TestRenewalsTeam',Renewals_Account_Manager__c='TestRenewalsAccountManager');
        insert a;
        Contact c = new Contact(AccountId=a.id,LastName='Test',Job_Function__c='TestJobFunction',Department__c='TestDepartment');
        insert c;
            Opportunity O = new Opportunity(Name='TestPipelineChange',AccountId=a.id,End_User__c=a.id,
            Contact__c=c.id,CloseDate=System.today(),Type='New Customer',Order_Type__c='New',
            Lead_Source_Category__c='Existing Customer',StageName='Create',Primary_Business_Driver__c='Test');
        insert O;
//COMMENT: Inserting the record with should have caused trigger to fire which means you can move on to the verification steps
//COMMENT:  Verify correct action using System asserts (these make sure your trigger did what it is supposed to)
//COMMENT:  first, we locate the Pipeline Change record that has been added
       OpportunityPipeline_Change__c pc = [select Stage_After__c from OpportunityPipeline_Change__c
            where Opportunity__c = :O.Id];
//COMMENT:  then we assert that the field we updated equals the field it was updated from
        System.assert(pc.stage_after__c == 'Create');
    }
}

Thanks
Subhash GarhwalSubhash Garhwal
You need to insert OpportunityPipeline_Change__c record before your query in class.

OpportunityPipeline_Change__c oPC = new OpportunityPipeline_Change__c (Opportunity__c = o.Id, Other Required Fields);
insert oPC;

Vinit_KumarVinit_Kumar
What is your trigger supposed to do Is it inserting the OpportunityPipeline_Change__c record or something else ??