function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
niven sfniven sf 

update checkbox in contact based on community user email of that contact

Parag Bhatt 10Parag Bhatt 10
Hi niven,
You haven't given full specification of your requirement.Requirement which i understood is to update checkbox  in contact if that contact's community user email has same email as of contact email.

Code Has been attached below:-
trigger updatecontactcheck on Contact(before update){
	set<id> setid = new set<id>();
	set<string> setcontact = new set<string>();
map<id,string>mapcontactid = new map<id,string>(); 

	for(Contact con:Trigger.new){
		setid.add(con.id);
		mapcontactid(con.id,con.email);
	}
	
	if(setid.size>0){
		for(user u :[select id,name,email from user where id IN :userinfo.getuserid() AND Contactid!=null AND contactid IN :mapcontactid.keyset() AND email IN :mapcontactid.values() ]){
		
		setcontact.add(u.email);
		}
	}
	if(setcontact.size()>0){
		for(Contact con:trigger.new){
			if(setcontact.containskey(con.email)){
				con.checkbox = TRUE;
			}
		}
	}
}
It will work as expected :)

Please let us know if this will help you.

Thanks,
Parag Bhatt
 
niven sfniven sf
is it necessary to put lookup for user in contact object
Parag Bhatt 10Parag Bhatt 10
Hi niven,
No buddy not at all actually we can see current user in contact by "lastmodified by" field in contact record. :)

Please let us know if this will help you.

Thanks,
Parag Bhatt
niven sfniven sf
This code is not working getting errors in this.
niven sfniven sf
Hello Parag Bhatt,

   The above code is not working to me. I am working on community user not system user. the existing contact email is having community user or not.