You need to sign in to do that
Don't have an account?
Igor M.
Apex Trigger unable to find Campaign Members with a specific status
I have a trigger and a test class, neither of which is able to do a soql query to find a campaign member with the status 'registered'
The trigger works, but on UI it completely ignores the status part and just updates the campaign member anyway, while in test class it fails since it doesn't find any with this status. Am I just misunderstanding how the status gets populated?
Here is the query in my trigger:
List<CampaignMember> cmList = [SELECT Id, PE_Changed__c, ContactId, Status
FROM CampaignMember
WHERE Status = 'Registered'];
Here is my setup in the test class:
CampaignMember cm1 = new CampaignMember ();
cm1.ContactId = testcon1.Id;
cm1.CampaignId = testCampaign.id;
cm1.Status = 'Registered';
insert cm1;
When I run the test class and look at the debug log, I see this:
08:02:44:449 USER_DEBUG [85]|DEBUG|cm1: CampaignMember:{ContactId=0032a0000066rW1AAI, CampaignId=7012a000000A8kuAAC, Status=Registered, Id=00v2a000000T1yTAAS}
So I know the setup worked and the status is correctly set. The other interesting part is that if I change my trigger to Status = 'Sent' then it works fine.
We are using AAkonsult Campaign Status app to change campaign statuses, but I don't believe that this should cause any issues.
Any help would be appreciated as I'd like to prevent making so many updates on records that don't need to be updated.
The trigger works, but on UI it completely ignores the status part and just updates the campaign member anyway, while in test class it fails since it doesn't find any with this status. Am I just misunderstanding how the status gets populated?
Here is the query in my trigger:
List<CampaignMember> cmList = [SELECT Id, PE_Changed__c, ContactId, Status
FROM CampaignMember
WHERE Status = 'Registered'];
Here is my setup in the test class:
CampaignMember cm1 = new CampaignMember ();
cm1.ContactId = testcon1.Id;
cm1.CampaignId = testCampaign.id;
cm1.Status = 'Registered';
insert cm1;
When I run the test class and look at the debug log, I see this:
08:02:44:449 USER_DEBUG [85]|DEBUG|cm1: CampaignMember:{ContactId=0032a0000066rW1AAI, CampaignId=7012a000000A8kuAAC, Status=Registered, Id=00v2a000000T1yTAAS}
So I know the setup worked and the status is correctly set. The other interesting part is that if I change my trigger to Status = 'Sent' then it works fine.
We are using AAkonsult Campaign Status app to change campaign statuses, but I don't believe that this should cause any issues.
Any help would be appreciated as I'd like to prevent making so many updates on records that don't need to be updated.
Status field is picklist in CampaignMember object so have you added 'Registered' value in that picklist and activate that.