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
amateur1amateur1 

test case help

this is my trigger plz help with the test case

 

trigger Assert_Update on Opportunity (after update) {

if(trigger.isupdate)
{
for(Opportunity o1:trigger.new)
{
 opportunity o=[select id,Accountid,Name,Manager__r.name,Sales_Consultan__r.name,
                       Process_Consultant_User__r.name,Process_Consultant_Manager__r.name,
                       Branch__c,Payment_Option__c,Sales_Date__c,Process_Stage__c from opportunity where id=:o1.id];
                       
                       
                       
asset a= [select id,name,Accountid,Sales_Consultant__c,Sales_Consultant_Manager__c,Process_Consultant__c,
          Process_Consultant_Manager__c,Branch__c,Payment_Option__c,Expected_Sale_Date__c,Process_Stage__c,opportunity__c from asset where opportunity__c=:o1.id];
 a.name=o.name;
 a.Accountid=o.Accountid;
 a.Sales_Consultant__c=o.Sales_Consultan__r.name;
 a.Sales_Consultant_Manager__c=o.Manager__r.name;
 a.Process_Consultant__c=o.Process_Consultant_User__r.name;
 a.Process_Consultant_Manager__c=o.Process_Consultant_Manager__r.name;
 a.Branch__c=o.Branch__c;
 a.Payment_Option__c=o.Payment_Option__c;
 a.Expected_Sale_Date__c=o.Sales_Date__c;
 a.Process_Stage__c=o.Process_Stage__c;
 a.opportunity__c=o.id;
update a;
}
}
}

 

mitumitu

Hi create oppertunity ,asset call the trigger

amateur1amateur1

this is the test case i have writte but i am getting this error plz resolve

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Assert_Update: execution of AfterUpdate caused by: System.QueryException: List has no rows for assignment to SObject Trigger.Assert_Update: line 13, column 1: []

@isTest
private class  Assert_Update_TC {
static testMethod void validateabc() {
Branch__c b= new Branch__c();
b.Name='sdf';
b.Branch_Code__c='xc';
b.City__c='df';
b.City__c='ww';
b.Pin_Code__c='wewe';
b.Invoice_Number_Cash__c=23;
b.Invoice_Number_General__c=23;
b.Invoice_Number_Online__c=23;
insert b;


account a= new account();
a.name='dsad';
insert a;
user u = [select id from user limit 1];

opportunity o = new opportunity();
o.Name='ssd';
o.CloseDate=date.ValueOf('2011-09-21');
o.Branch__c=b.id;
o.Manager__c=u.id;
o.Payment_Option__c='Full Payment';
o.StageName='Follow up for Evaluation';
o.Accountid=a.id;
insert o;
update o;
 
asset a1 = new asset();
a1.name=o.name;
a1.accountid=a.id;
a1.opportunity__c=o.id;
insert a1;

update a1;


}
}

 

Rajesh SriramuluRajesh Sriramulu

Hi

 

create some new records in UI so that  it will fetch those records in test classes.

 

Let me know any issue and if it solves ur problem plz accept it solution.

amateur1amateur1

i dint get u plz can u give me code

Rajesh SriramuluRajesh Sriramulu

Hi

 

 

U just  create some opputunities and assets records as according in trigger so that it will get some records to fetch in test class.

 

 

Let me know any issue and if it solves ur problem plz accept it solution.

SamuelDeRyckeSamuelDeRycke

I think the problem is in your trigger code:

 

//you should verify if this actually returns something .. 

asset a= [select id,name,Accountid,Sales_Consultant__c,Sales_Consultant_Manager__c,Process_Consultant__c,
          Process_Consultant_Manager__c,Branch__c,Payment_Option__c,Expected_Sale_Date__c,Process_Stage__c,opportunity__c from asset where opportunity__c=:o1.id];
 a.name=o.name;
 a.Accountid=o.Accountid;

//in the case of your test scenario, you're not able to access your organisation data, but only the data you create within the test code.