You need to sign in to do that
Don't have an account?
Prasanth Reddy M
Error while testing trigger in sandbox
I have received below error, when testing below trigger.
Trigger:
trigger CampaignMemberTaskCreation on CampaignMember (after update) {
list<Task> AddTask=new List<Task>();
for(CampaignMember CM : Trigger.new) {
if(cm.Status == 'Responded'){
AddTask.add(new Task(
WhoId = CM.ContactId,
Status = 'Completed',
Description='CM.Description',
Subject = 'Call - ' + CM,
Whatid= CM.CampaignId));
}
}
insert AddTask;
}
Error Message, when tried to update the campaign member status:
Sandbox
Apex script unhandled trigger exception by user/organization: 00570000003003D/00D190000000OrW Source organization: 00D700000008ieh (null)
CampaignMemberTaskCreation: execution of AfterUpdate
caused by: System.DmlException: Insert failed. First exception on row 0; first error: STRING_TOO_LONG, Subject: data value too large: Call - CampaignMember:{Id=00v19000000TEZkAAO, IsDeleted=false, CampaignId=70119000000A3qoAAC, LeadId=00Q19000001eGJWEA2, ContactId=null, Status=Responded, HasResponded=true, CreatedDate=2015-10-15 16:55:39, CreatedById=00570000003003DAAQ, LastModifiedDate=2016-01-25 09:59:56, LastModifiedById=00570000003003DAAQ, SystemModstamp=2016-01-25 09:59:56, FirstRespondedDate=2016-01-25 00:00:00, Name=null, Email__c=false} (max length=255): [Subject]
Trigger.CampaignMemberTaskCreation: line 14, column 1
How i can resolve the exception here?
Trigger:
trigger CampaignMemberTaskCreation on CampaignMember (after update) {
list<Task> AddTask=new List<Task>();
for(CampaignMember CM : Trigger.new) {
if(cm.Status == 'Responded'){
AddTask.add(new Task(
WhoId = CM.ContactId,
Status = 'Completed',
Description='CM.Description',
Subject = 'Call - ' + CM,
Whatid= CM.CampaignId));
}
}
insert AddTask;
}
Error Message, when tried to update the campaign member status:
Sandbox
Apex script unhandled trigger exception by user/organization: 00570000003003D/00D190000000OrW Source organization: 00D700000008ieh (null)
CampaignMemberTaskCreation: execution of AfterUpdate
caused by: System.DmlException: Insert failed. First exception on row 0; first error: STRING_TOO_LONG, Subject: data value too large: Call - CampaignMember:{Id=00v19000000TEZkAAO, IsDeleted=false, CampaignId=70119000000A3qoAAC, LeadId=00Q19000001eGJWEA2, ContactId=null, Status=Responded, HasResponded=true, CreatedDate=2015-10-15 16:55:39, CreatedById=00570000003003DAAQ, LastModifiedDate=2016-01-25 09:59:56, LastModifiedById=00570000003003DAAQ, SystemModstamp=2016-01-25 09:59:56, FirstRespondedDate=2016-01-25 00:00:00, Name=null, Email__c=false} (max length=255): [Subject]
Trigger.CampaignMemberTaskCreation: line 14, column 1
How i can resolve the exception here?
It can be clearly seen from your code that you are appending the whole instane of your CampaignMember object i.e. CM in your task subject which leads to the limit exceed.
I have modified your code to avoid this error, Please change your trigger codce with below code : Please let me know if you any issue with the above code.
Thanks,
Abhishek Bansal.
All Answers
It can be clearly seen from your code that you are appending the whole instane of your CampaignMember object i.e. CM in your task subject which leads to the limit exceed.
I have modified your code to avoid this error, Please change your trigger codce with below code : Please let me know if you any issue with the above code.
Thanks,
Abhishek Bansal.
Class CampaignMemberTaskcreation
Method Name testtask
Pass/Fail Fail
Error Message System.NullPointerException: Attempt to de-reference a null object
Stack Trace Class.CampaignMemberTaskcreation.testtask: line 22, column 1
Here is the class :
@isTest
public class CampaignMemberTaskcreation {
Static testmethod void testtask(){
Contact co1 = new Contact(
LastName = 'Last',
Title='CEO');
insert co1;
string co1Id = co1.id;
Campaign ca1 = new Campaign(
Name = 'Testcampaign',
Date_Sent__c=Date.today(),
IsActive = TRUE);
insert ( ca1 );
string ca1Id = ca1.id;
CampaignMember m1 = new CampaignMember();
m1.Contact.Id = co1.Id;
m1.Campaign.Id = ca1.Id;
m1.status='Responded';
insert m1;
}
}
Could you please let me know, how i can correct the test class ?