1

enter image description here

I've been having this problem for some time now. Right now this trigger is sitting on prod, and has recently broke I have tried to rewrite the trigger, re write the test class but I can't figure out how to fix it. What else should I be looking at/taking into consideration with this trigger.

After doing some research about this topic I found a bunch of posts but none of them help. Such as adding isActive = true. The following is my trigger, which I think my logic will work. Could someone give me some guidance on how to properly test this?

I asked this question recently located here, and I was told I can't do it this way but it is all working up to

if(groupMap.containsKey(ld.CreatedById))

After this point it doesn't get into my condition, which is why I need help with my test class.

So in the end Is this possible?

Side note -- No one in my company really knows what a "PowerPartner" even is, and aren't sure who wrote this trigger originally, and im just trying to put out the fire. I'm only trying to fix it so I can deactivate it through a changeset

Should I be looking at something else besides the trigger.

Trigger

trigger PartnerLeadShare on Lead (after insert,after update) {

if(Trigger.isAfter){
List<LeadShare> leadShareList = new list<LeadShare>();   
    Set<id>pUserMap=new set<id>();  
      for(User u: [select id,UserType,isActive from user where UserType = 'PowerPartner' and IsActive = True]){       
               {
                pUserMap.add(u.id);  
                System.debug('pUserMap ' +pUserMap);
        }
      }
  Map<Id, GroupMember> groupMap = new Map <Id, GroupMember>();
for(GroupMember grp : [select GroupId, UserOrGroupId from GroupMember where UserORGroupID IN:pUserMap]){
    groupMap.put(grp.UserOrGroupId, grp);
    }
System.debug('groupList    '+groupMap ); 
if(pUserMap != null){
    //System.debug('Inside PartUserMap != null');
    for(Lead ld: trigger.new){  
        System.debug('Created BY!!  ' +ld.CreatedById);  
         if(groupMap.containsKey(ld.CreatedById)){    
                System.debug('Inside GroupMap Contains');          
                LeadShare ldShare = new LeadShare (LeadId = ld.id, LeadAccessLevel = 'Edit');   
                leadShareList.add(ldShare ); 
            }       
    } 
} 

Test Class

 static testMethod void myUnitTest1() {     

Profile p = [SELECT Id FROM Profile WHERE Name='Disti Partner'];  

List<Lead> leadList = new List<Lead>();
List<LeadShare> leadShareList = new list<LeadShare>();  

for(integer i =0; i<3; i++){ 
Lead ld = new Lead();
ld.lastName = 'Tester';  
ld.Company = 'Debbie TestRep';
ld.Status = 'Open';
ld.Program_EAU__c ='11';

insert ld;
system.debug('ld****' +ld);

GroupMember groupMemberStore = [select GroupId,UserOrGroupId from GroupMember limit 1];
LeadShare ls = new LeadShare(); 
ls.LeadId = ld.id;
ls.UserOrGroupId = groupMemberStore.UserOrGroupId ;
ls.LeadAccessLevel = 'Edit';
system.debug('ls ++!@+!  '  +ls); 
insert ls;
3
  • Related to your side-note about the mysterious "PowerPartner" user type, it's a type of user who is accessing the org through the Partner Portal or through Communities. See the UserType attribute on the User object documentation here: salesforce.com/us/developer/docs/api/Content/…
    – Mark Pond
    Commented Apr 28, 2014 at 17:34
  • Yea that's mine, I never got a answer and it wasn't going any where.. I re-wrote the trigger and I'm trying to get more help
    – EricSSH
    Commented Apr 28, 2014 at 17:47
  • Duplicate question? 2 different pieces of code. I never accepted a answer on that other page and I reworded it..
    – EricSSH
    Commented Apr 28, 2014 at 22:52

0

Browse other questions tagged .