You need to sign in to do that
Don't have an account?
Pallavi singh
Trigger Test Class with an "Invalid Parameter value"
Hi,
This is the trigger
trigger No_Contacts_Not_Related_to_Account on Task (before insert, before update) {
List<Task> tList = trigger.new;
List<Id> idList = new List<Id>();
for(Task t : tList) {
if(t.whoId != null) idList.add(t.whoId);
}
Map<Id, Contact> cMap = new Map<Id, Contact>([select id, accountId from contact where Id in: idList]);
List<Task> tList_failed = new List<Task>();
for(Task t : tList) {
if(t.whoId != null && t.whatId != null && t.whatId != cMap.get(t.whoId).accountId) tList_failed.add(t);
}
if(tList_failed.size() > 0) tList[0].addError('Achtung: Ansprechpartner ist nicht beim ausgewählten Debitor hinterlegt ');
}
And here is the Test class but i get this error message "invalid Parameter value" dont know why.
@isTest
Private class No_Contacts_Not_Related_to_Account_Test {
static testMethod void testTrigger() {
// Create test Account
Account acc = new Account(Name = 'Test Account');
insert acc;
// Create test Contact related to Account
Contact con = new Contact(FirstName = 'Test', LastName = 'Contact', AccountId = acc.Id);
insert con;
// Create test Contact not related to Account
Contact con2 = new Contact(FirstName = 'Test2', LastName = 'Contact2');
insert con2;
// Create test Tasks with related and not related Contacts
Task t1 = new Task(Subject = 'Test Task 1', WhoId = con.Id, WhatId = acc.Id);
Task t2 = new Task(Subject = 'Test Task 2', WhoId = con2.Id, WhatId = acc.Id);
Test.startTest();
// Insert Tasks and verify that the trigger throws an error on t2
try {
insert new List<Task>{t1, t2};
System.assert(false, 'Expected error was not thrown');
} catch (DmlException e) {
System.assertEquals('Achtung: Ansprechpartner ist nicht beim ausgewählten Debitor hinterlegt ', e.getMessage());
}
Test.stopTest();
}
}
Need help with this test class
Thank you
This is the trigger
trigger No_Contacts_Not_Related_to_Account on Task (before insert, before update) {
List<Task> tList = trigger.new;
List<Id> idList = new List<Id>();
for(Task t : tList) {
if(t.whoId != null) idList.add(t.whoId);
}
Map<Id, Contact> cMap = new Map<Id, Contact>([select id, accountId from contact where Id in: idList]);
List<Task> tList_failed = new List<Task>();
for(Task t : tList) {
if(t.whoId != null && t.whatId != null && t.whatId != cMap.get(t.whoId).accountId) tList_failed.add(t);
}
if(tList_failed.size() > 0) tList[0].addError('Achtung: Ansprechpartner ist nicht beim ausgewählten Debitor hinterlegt ');
}
And here is the Test class but i get this error message "invalid Parameter value" dont know why.
@isTest
Private class No_Contacts_Not_Related_to_Account_Test {
static testMethod void testTrigger() {
// Create test Account
Account acc = new Account(Name = 'Test Account');
insert acc;
// Create test Contact related to Account
Contact con = new Contact(FirstName = 'Test', LastName = 'Contact', AccountId = acc.Id);
insert con;
// Create test Contact not related to Account
Contact con2 = new Contact(FirstName = 'Test2', LastName = 'Contact2');
insert con2;
// Create test Tasks with related and not related Contacts
Task t1 = new Task(Subject = 'Test Task 1', WhoId = con.Id, WhatId = acc.Id);
Task t2 = new Task(Subject = 'Test Task 2', WhoId = con2.Id, WhatId = acc.Id);
Test.startTest();
// Insert Tasks and verify that the trigger throws an error on t2
try {
insert new List<Task>{t1, t2};
System.assert(false, 'Expected error was not thrown');
} catch (DmlException e) {
System.assertEquals('Achtung: Ansprechpartner ist nicht beim ausgewählten Debitor hinterlegt ', e.getMessage());
}
Test.stopTest();
}
}
Need help with this test class
Thank you
Can you confirm where excatly you are getting error? Is it while running the test class?
Thanks,
I m unable to save the trigger
Thanks,
I dont think this error is related to this trigger and test class. Because I was able to save with out any errors. Also the Class name itself is different in the error.
Let me know if you face any issues.
Thanks,
But its not coverage is still 0%
Do you know why?
Thanks,
Can you try below test clas.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
Were you able to get coverage for trigger.
Thanks
It's not working i get this error message.
Thanks,
Did you try the same test class which I shared because I dont see any method called testtrigger in my test class.
Thanks,