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;
}
}
}
}
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:- It will work as expected :)
Please let us know if this will help you.
Thanks,
Parag Bhatt
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
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.