You need to sign in to do that
Don't have an account?
amzy
hi i have a trigger updating contact photo by mapping with Email id, i need test class for this trigger. Can anyone help on this please? code is below -
trigger contactTrigger on Contact (before insert,before Update) {
if(RecursiveTrigger.isFirst){
if(Trigger.isInsert || Trigger.isUpdate){
List<String> emailList = new List<String>();
for(Contact c:Trigger.new){
emailList.add(c.Email);
}
System.debug('email====>>>>'+emailList);
Map<String,User> userMap = new Map<String,User>();
List<User> objUser = [Select id,email,FullPhotoUrl from User where Email in: emailList];
for(User u:objUser){
if(u.FullPhotoUrl != null)
userMap.put(u.email,u);
}
List<Contact> objContactList = new List<Contact>();
for(Contact c:Trigger.new){
if(userMap.containskey(c.Email))
c.Photo_Url__c = userMap.get(c.Email).FullPhotoUrl;
}
}
}
}
if(RecursiveTrigger.isFirst){
if(Trigger.isInsert || Trigger.isUpdate){
List<String> emailList = new List<String>();
for(Contact c:Trigger.new){
emailList.add(c.Email);
}
System.debug('email====>>>>'+emailList);
Map<String,User> userMap = new Map<String,User>();
List<User> objUser = [Select id,email,FullPhotoUrl from User where Email in: emailList];
for(User u:objUser){
if(u.FullPhotoUrl != null)
userMap.put(u.email,u);
}
List<Contact> objContactList = new List<Contact>();
for(Contact c:Trigger.new){
if(userMap.containskey(c.Email))
c.Photo_Url__c = userMap.get(c.Email).FullPhotoUrl;
}
}
}
}
All Answers
Create a new User record by speciying a test url to FullPhotoUrl in Test class and then create a new contact finally verify that contact photo URL field has something copied from User object.
Hope this helps...!!
Please mark as best answer if the above helps..!!!
Use this code:
Let me know if it helps
Thanks!