• luc4
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 0
    Replies

Hi,

 

i have written a Campaign trigger that create some custom CampaignMemberStatus objects on the after insert event. Because apex
doesn't enforce crud/fls, normally we must manually take care of it (using describe methods). I'm not sure, but i can't find crud/fls settings for the CampaignMemberStatus object in the profile ui (nevertheless Schema.sObjectType.CampaignMemberStatus seems
to exist). This means also there is no possibilty to writte unit tests with different profiles to verify behaviour.

 

Is CampaignMemberStatus a special case, something like a dependent object from a Campaign? Is it neccessary to manually ensure the crud/fls settings in the campaign trigger code, which is creating the CampaignMemberStatus objects?

 

The code is used in a package and must pass the security review.

 

Thanks for your help,
Greetings Luca

  • February 16, 2013
  • Like
  • 0

I have the requirement to set a custom CampaignMemberStatus ('Duplicate') for new added duplicate CampaignMembers (duplicate in my case means the underlying Contac/tLead have the same email address).

 

Because a CampaignMember trigger can contain CampaignMembes from different campaigns i'm not sure what will be the best/efficent way to query the already existing CampaignMembers without hitting governer limits.

 

My first thoughts are:

1. Collecting all email addresses that are existst in current the trigger bulk.

2. Collecting all campaign ids that are exist in the current trigger bulk.

3. Querying all CampaignMembers that uses an email address from the current bulk and are in a campaign from the current bulk.

 

Something like this:

SELECT Id, campaignId, email__c
FROM CampaignMember
WHERE CampaignId IN :campaignIds
AND email__c IN :emailAddresses
AND Status != 'DUPLICATE'
AND email__c != null

 

 

Notes about the query:

1. email_c is a formula field which contains the email address from the underlying object depending if the object is a Contact or Lead.

2. select all members that are IN the bulk campaign ids _AND_ are IN the bulk email addresses.

4. exclude already as duplicate marked members (only get the originals) to reduce the result even more (to know there exists at least one member with this email address is sufficient).

 

I'm aware of that the condition in 2. will also fetching members that are not interesting for me (example: member with email 'a' that is in campaign 'b', but the bulk contains the email 'a' only for campaign 'c'). So i must check the result against the current bulk in apex afterwards (check if member in same campaign with same email).

 

But i think this should be ok or at least should not break the govenor limits.

 

 

In a worst case scenario we can have a bulk with:

1. 200 members from different campaigns.

2. each member has a different email.

3. each of the 200 campaigns contain at least 200 members with this email addresses.

 

So this would mean that we can get a maximum query result of 40000 members (limit is 50000). Because we also must iterate over the result (to check against the current bulk) we must also keep the logic there very keen/compact to not hit the script lines limit. I think the heap limit can also be passed by using a soql loop.

 

For me this approach looks very complex for on the first sight very simple requirement. Because i'm new to apex development i'm also not so confident in my expectations about the limits. ;)

 

I would be happy to hear any thoughts on this approach and i'm also open to other solutions for the problem.

 

Thanks for taking the time to read this!

 

Greetings

Luca

 

P.S. The code should run in a managed package and therefore it should be robust and also pass the security review!

  • January 26, 2013
  • Like
  • 0