You need to sign in to do that
Don't have an account?
Deployment Failed for the following code
I am getting this error and it fails the deployment of my code, what am I missing to get this working?
Class NameMethod NameError MessageABSI_TEST_MassTaskControllermyUnitTestSystem.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Cannot create a portal user without contact: [ContactId]
Stack Trace: Class.ABSI_TEST_MassTaskController.myUnitTest: line 68, column 1
It is failing on the following code:
trigger CaseTeamAddition on Case (after insert) {
if (Trigger.isAfter){
If (Trigger.isInsert){
CaseTeamRole caseTeamRole = [SELECT Id
FROM CaseTeamRole
WHERE Name = 'Case Update Team'
LIMIT 1];
List<Id> accountIdList = new List<Id>();
For (Case currentCase : Trigger.new){
accountIdList.add(currentCase.AccountId);
}
List<Contact> contactList = [SELECT Id
FROM Contact
WHERE AccountId IN : accountIdList
AND Get_Email_Updates__c = true];
List<CaseTeamMember> caseMembersToInsert = new List<CaseTeamMember>();
For (Case currentCase : Trigger.new){
For (Contact currentContact : contactList){
If (currentContact.AccountId == currentCase.AccountId){
CaseTeamMember newMember = new CaseTeamMember(ParentId = currentCase.Id,
MemberId = currentContact.Id,
TeamRoleId = caseTeamRole.Id);
caseMembersToInsert.add(newMember);
}
}
}
if (caseMembersToInsert.size() > 0){
insert caseMembersToInsert;
}
}
}
}
As per my understanding in following test class ABSI_TEST_MassTaskController you are inserting portal user record at line no 68.
Without adding a contact id to the user.
Please add contact id in user record and check once.
For better understanding please post your sample test class code.
I hope it helps you.
Please let me know in case of other help.
Thanks
Varaprasad
All Answers
As per my understanding in following test class ABSI_TEST_MassTaskController you are inserting portal user record at line no 68.
Without adding a contact id to the user.
Please add contact id in user record and check once.
For better understanding please post your sample test class code.
I hope it helps you.
Please let me know in case of other help.
Thanks
Varaprasad