Skip to main content
Hi,

 

I have wrote an apex class .

 

Someone, guide me to write an unit test case.

 

Apex Class:

 

public class TriggerHandlerOnUser {

 

    public void detailOfUser(List<User> userList){

 

        List<Employee__c> EList=new List<Employee__c>();

 

        List <String> EmailList = new List<String>();

 

        for(User usr:userList){

 

            EmailList.add(usr.Email);

 

        }

 

         Map<String, Employee__c> m = new Map<String , Employee__c>();

 

        for (Employee__c emp : [select Email_ID__c, Name from Employee__c where Email_ID__c IN : EmailList] ){

 

             m.put(emp.Email_ID__c, emp);

 

        }

 

        for(User u:userList){

 

            if(m.containsKey(u.Email))

 

        {

 

            Employee__c ep=new Employee__c();         

 

            ep=m.get(u.Email);

 

            ep.Phone__c=u.Phone;

 

            ep.Name=u.FirstName;

 

            ep.Last_Name__c=u.LastName;

 

            ep.Email_Id__c=u.Email;

 

            EList.add(ep);

 

        }

 

            else{

 

                EList.add(new Employee__c(

 

                Name=u.FirstName,

 

                Last_Name__c=u.LastName,

 

                Phone__c=u.Phone,

 

                Email_Id__c=u.Email,

 

                User__c=u.id

 

            ));

 

            }

 

        }

 

        upsert Elist;

 

    }

 

}
3 件の回答
  1. 2020年9月19日 16:00
    Hi Pallavi,

     

    Hope you get the answer, Could you please mark the solution as Best Answer to close this.
0/9000