Skip to main content
We do not allow users to delete camapgin members unless its a Sys Admin

 

We would like to open this function to certain users with permission Set "Delete Campaign Members"

 

I created the permission set assigned it to a user with custome proflie"XYZ" but I run into a error from this apex code. How do I go around this or modify this code to account the permission set

 

 private void oldHandler_OnAfterDelete(List<CampaignMember> oldItems)

 

    { 

 

        map<ID,ID> mapAdminProfIDs = new map<ID,ID>();

 

        for(Profile item: [Select Name, Id From Profile where Name in ('System Administrator', 'System Administrator (SSO)')])

 

        {

 

            mapAdminProfIDs.put(item.id, item.id);

 

        }

 

        

 

        if(!mapAdminProfIDs.containsKey(UserInfo.getProfileId()))

 

        {

 

            Set<ID> setCampIDs = new Set<ID>(); 

 

            for(CampaignMember item:oldItems){ setCampIDs.add(item.CampaignId);}

 

            

 

            map<ID,ID> mapTLCampaigns = new map<ID,ID>();

 

            for(Campaign item: [Select c.Type, c.Id From Campaign c where id in :setCampIDs])

 

            {

 

                if(item.Type != 'Event' && item.Type != 'ABC')

 

                {

 

                    oldItems[0].CampaignID.addError('You are not allowed to delete these subscriptions.');

 

                }

 

                else if(item.Type == 'ABC') mapTLCampaigns.put(item.ID, item.ID);

 

            }
1 respuesta
  1. 14 may 2018, 20:19
    @Pooja, use Hierarchy type custom setting, where you have to mention these 2 profile and users you are assigning permission set. You can name that custom setting like 'Campaign Delete Permission'. Also, you have to modify your code accordingly. Let me know if it helped.
0/9000