You need to sign in to do that
Don't have an account?
Ivan Winzer
My test class
So below is the test class created to test my credit card trigger. I keep getting a assert error but looking at it im wondering if im doing way more then needed in the test. Below is the test class
@isTest
public class Test_CreditCardTrigger{
@isTest
public static void testCreateCreditCard(){
Account a = new Account(Name = 'Test MainContactTrigger');
insert a;
Contact c = new Contact(AccountId = a.id, firstName = 'Test MainContactTrigger', lastName = 'Tester');
insert c;
authnet_credit_card__c cc = new authnet_credit_card__c( Contact__c = c.id);
insert cc;
c = [select AccountId,Account.Name from Contact where id = :c.id limit 1];
System.assertEquals('Test MainContactTrigger', c.Account.Name);
System.assertEquals(a.id, c.AccountId);
}
}
@isTest
public class Test_CreditCardTrigger{
@isTest
public static void testCreateCreditCard(){
Account a = new Account(Name = 'Test MainContactTrigger');
insert a;
Contact c = new Contact(AccountId = a.id, firstName = 'Test MainContactTrigger', lastName = 'Tester');
insert c;
authnet_credit_card__c cc = new authnet_credit_card__c( Contact__c = c.id);
insert cc;
c = [select AccountId,Account.Name from Contact where id = :c.id limit 1];
System.assertEquals('Test MainContactTrigger', c.Account.Name);
System.assertEquals(a.id, c.AccountId);
}
}
System.AssertException: Assertion Failed: Expected: Test MainContactTrigger, Actual: Test MainContactTrigger Tester
The below code is working fine. I commented authnet_credit_card__c insertion because I don't have this object in my org.
Where are you getting error
in contact the name of lookup field is Account not AccountId. Maybe that's where the problem is.
Regards
System.AssertException: Assertion Failed: Expected: 001e000000LMW5GAAX, Actual: 001e000000LMW5HAAX
which i know means the account ID that was created for the account does no match the one for the contact but what i dont see is why if im creating the contact on that account.
Intially when you are creating the contact use
Account = a.id
and in the query also use Account.
and if still this does not work re-Query the value of the id form the database.
I am quite sure that it will work.
And if it still does'nt send me your updated code.
Regards
Everytime i make the change as you specified above with Account = a.id i get the error of not being able to use a sobject in single querie.
Error: Compile Error: Invalid initial expression type for field Account, expecting: SOBJECT:Account (or single row query result of that type) at line 8 column 43