You need to sign in to do that
Don't have an account?
Reshmi Smiju
How to Refrence Lookup Field in AssetEquals Method.
Hi.
I have a custome object called Rival_c which is having a lookup relation with account on the field Rival_c. While writing a test class for a trigger , SOQL Query (mensioned below)has been written following with assertEquals method. But i am not sure, how to reference the lookup fields value in the assertEquals method.
@isTest
public class TestGetRivalValue {
static testMethod void TestGetRivalValuemthd(){
Rival__c riv = new Rival__c();
riv.Name = 'Best';
insert riv;
Account acc1 = new Account();
acc1.Name= 'test rivalss';
acc1.Rival_Picklist__c ='Best';
insert acc1;
List<Account> accs = new List<Account>();
for (Integer i=0;i<200;i++){
Account acc= new Account();
acc.Name= 'test rivalss';
acc.Rival_Picklist__c ='Best';
accs.add(acc);
}
insert accs;
List <Account> newaccs = new List<Account>();
newaccs = [SELECT Id, Rival_Picklist__c, Rival__r.Name FROM Account]; ******** Hope this line is correct.
for (Account a:newaccs){
System.assertEquals(a.Rival__r.Name,a.Rival__c); ******* This is i am not sure, how to incoporate the lookup value.
}
}
}
Expected value should be the Name (System field) in the Rival_c Object.
Actual value should be the Rival_c Lookup field in the Account Object.
Pls let me know.
Thanks In Advance
Reshmi
I have a custome object called Rival_c which is having a lookup relation with account on the field Rival_c. While writing a test class for a trigger , SOQL Query (mensioned below)has been written following with assertEquals method. But i am not sure, how to reference the lookup fields value in the assertEquals method.
@isTest
public class TestGetRivalValue {
static testMethod void TestGetRivalValuemthd(){
Rival__c riv = new Rival__c();
riv.Name = 'Best';
insert riv;
Account acc1 = new Account();
acc1.Name= 'test rivalss';
acc1.Rival_Picklist__c ='Best';
insert acc1;
List<Account> accs = new List<Account>();
for (Integer i=0;i<200;i++){
Account acc= new Account();
acc.Name= 'test rivalss';
acc.Rival_Picklist__c ='Best';
accs.add(acc);
}
insert accs;
List <Account> newaccs = new List<Account>();
newaccs = [SELECT Id, Rival_Picklist__c, Rival__r.Name FROM Account]; ******** Hope this line is correct.
for (Account a:newaccs){
System.assertEquals(a.Rival__r.Name,a.Rival__c); ******* This is i am not sure, how to incoporate the lookup value.
}
}
}
Expected value should be the Name (System field) in the Rival_c Object.
Actual value should be the Rival_c Lookup field in the Account Object.
Pls let me know.
Thanks In Advance
Reshmi
Try to use this
All Answers
Try to use this
Forgot to add the Relationship Id. :(