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


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 PartnerLeadShare on Lead (after insert,after update) {

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]){       
                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);  
                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;
  • 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
    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
    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
    Apr 28, 2014 at 22:52


Browse other questions tagged .