You need to sign in to do that
Don't have an account?
tsalb
Test - Assertion Failed: Expected:null
I need some help wrapping my head around testing this trigger - I seem to have prepared and inserted my dataset correct, but I'm not sure why it's giving me an error of "Expected:Null".
My Trigger (working in sandbox, manually inserting records)
trigger AddCountyId on Contact (before insert, before update) { Set<String> CountyIds = new Set<String>(); for(Contact c : Trigger.new) { CountyIds.add(c.fdicCountyID__c); } Map<String, Id> countyMap = new Map<String,Id>(); //Add both sets of IDS to above Map for(County__c cty : [SELECT cty.Id, cty.fdicCountyID__c FROM County__c cty WHERE cty.fdicCountyID__c != null AND cty.fdicCountyID__c IN :CountyIds]) { countyMap.put(cty.fdicCountyID__c, cty.Id); } //Update Primary County on the Contact with County ID for(Contact updateC : Trigger.new) { try { if(updateC.fdicCountyID__c != null) { //Update Primary County with County Id from Map updateC.Primary_County__c = countyMap.get(updateC.fdicCountyID__c); } } catch (Exception e) { } } }
Stripped down test method in my test class
static testMethod void verifyCountyId() { //Create Test County County__c cty = new County__c(Name='Test County', Latitude__c = 1, Longitude__c = 1, fdicCountyId__c ='abcd1234'); insert cty; //Create Test Vendor Account vAcct = new Account(Name = 'Test Vendor Account'); insert vAcct; Contact v = new Contact(LastName = 'Vendor Demo', last_engaged_date__c = Date.today(), AccountId = vAcct.Id, fdicCountyId__c = 'abcd1234'); insert v; System.assertEquals (v.Primary_County_ID__c, cty.Id); }
I get a System.AssertException: Assertion Failed: Expected:null Actual: a0hJ000000FymvMac
Does anyone have any insight as to what i'm doing wrong?
When you insert the contact variable v, you get the ID back automatically, but you don't get any other field changes, so Primary_County_ID__c will be empty.
You need to requery the contact and specifically retrieve the Primary_County_ID__c field so you can compare it. You could do something like
All Answers
When you insert the contact variable v, you get the ID back automatically, but you don't get any other field changes, so Primary_County_ID__c will be empty.
You need to requery the contact and specifically retrieve the Primary_County_ID__c field so you can compare it. You could do something like
Thanks sir, did not know a query was necessary in this case. I had typed the wrong field as well, but this is snippet is working:
Failure Message: "System.AssertException: Assertion Failed: Expected: null, Actual:", Failure Stack Trace: "Class.RestClientTest.testGet: line 36, column 1"
am unable to solve the above error.Its working fine in sandbox. It has no errors but in production when I validate am getting this error. Please help me in resolving this.
Thank You,
Bindu
I am having a similiar problem. The code works fine on the Sandbox but on production it fails.
private class TestClass_ForAccountTechnicalProfile
{
static testmethod void test_Copy_AccountTechnicalProfile_OnAccount_trigger()
{
Account a = new Account();
a.Name='test - mumbai';
a.Site_City__c ='mumbai';
a.Type='End User';
insert a;
Account_Technical_Profile__c atp = new Account_Technical_Profile__c ();
atp.Account__c = a.Id;
insert atp;
//Verify that the results are as expected.
a = [Select Id,Copy_Account_Technical_Profile__c from Account where Id=:a.Id limit 1];
System.assertEquals(a.Copy_Account_Technical_Profile__c,atp.Id);
}
}