You need to sign in to do that
Don't have an account?

Need to Identify Contacts as a Community User
Hello,
I need a way to identify a Contact as an Active Community user. I've added a field called Partner Community User? on the contact that I want to flip whenever a Contact is enabled as a Partner User. I've written some code using a @future calls to bypass the setup object error.
I'm getting the
"cannot insert update activate entity" error in my trigger.
Apex Trigger
trigger flipContactPartnerActive on User (after update) { //List<Contact> potentialContacts = [SELECT id, name FROM Contact WHERE Account.IsPartner = true AND Status__c ='Active' AND Email !='' ]; //Map<Id, Contact> ContactMap = new Map<Id,Contact>(); Contact upcon = new Contact(); // for(Contact con:potentialContacts){ // if(con !=null){ // ContactMap.put(con.id, con); // } // } for(User usr: Trigger.new){ if(usr.IsActive == true && usr.ContactId !=null && usr.UserType =='PowerPartner'){ upcon.id = usr.ContactId; if(upcon != null){ utilPartnerClassTrue upt = new utilPartnerClassTrue(upcon.id); } } if(usr.IsActive == false && usr.ContactId !=null && usr.UserType =='PowerPartner'){ upcon.id = usr.ContactId; if(upcon != null){ utilPartnerClassFalse upf = new utilPartnerClassFalse(upcon.id); } } } }
APEX utillity classes
public class utilPartnerClassTrue { public utilPartnerClassTrue(Id cid){ List<ID> ContactID = new List<ID>{cid}; AddContactUserObject(ContactID); } @future private static void AddContactUserObject(List<id> cid){ Contact co = [SELECT id, Partner_Community_Access__c FROM Contact WHERE id = :cid[0] ]; if(co != null){ if(co.Partner_Community_Access__c != 'Yes'){ co.Partner_Community_Access__c = 'Yes'; system.debug(co); } update co; system.debug(co); } } }
public class utilPartnerClassFalse { public utilPartnerClassFalse(Id cid){ List<ID> ContactID = new List<ID>{cid}; AddContactUserObject(ContactID); } @future private static void AddContactUserObject(List<id> cid){ Contact co = [SELECT id,Partner_Community_Access__c FROM Contact WHERE id = :cid[0] ]; if(co != null){ if(co.Partner_Community_Access__c != 'No'){ co.Partner_Community_Access__c = 'No'; system.debug(co); } update co; } } }