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
Sudha#aSudha#a 

any one help write test class

u.Alias = um.ebMobile__UserCode__c;
                //u.Email= sfaSetting[0].UserEmail__c;
                u.LastName = um.ebMobile__LastName__c;
                u.EmailEncodingKey = sfaSetting[0].EmailEncodingKey__c;
                u.LanguageLocaleKey = sfaSetting[0].LanguageLocaleKey__c;
                //u.ProfileId =  sfaSetting[0].ProfileId__c;
                if(um.CountryCode__c=='AE')
                {
                    u.TimeZoneSidKey = 'Asia/Dubai';
                    u.LocaleSidKey = 'ar_AE';
                    u.UserName = (um.ebMobile__UserCode__c + '@coca-cola.co.ae.full').toLowerCase();
                    u.Email= (um.ebMobile__UserCode__c + '@coca-cola.co.ae.full').toLowerCase();
                }
                else if (um.CountryCode__c=='OM')
                {
                    u.TimeZoneSidKey = 'Asia/Dubai';
                    u.LocaleSidKey = 'ar_OM';
                    u.UserName = (um.ebMobile__UserCode__c + '@coca-cola.co.om.full').toLowerCase();
                    u.Email= (um.ebMobile__UserCode__c + '@coca-cola.co.om.full').toLowerCase();
                }
                else if (um.CountryCode__c=='BH')
                {
                    u.TimeZoneSidKey = 'Asia/Riyadh';
                    u.LocaleSidKey = 'ar_BH';
                    u.UserName = (um.ebMobile__UserCode__c + '@coca-cola.co.bh.full').toLowerCase();
                    u.Email= (um.ebMobile__UserCode__c + '@coca-cola.co.bh.full').toLowerCase();
                }
                else if (um.CountryCode__c=='QA')
                {
                    u.TimeZoneSidKey = 'Asia/Riyadh';
                    u.LocaleSidKey = 'ar_QA';
                    u.UserName = (um.ebMobile__UserCode__c + '@coca-cola.co.qa.full').toLowerCase();
                    u.Email= (um.ebMobile__UserCode__c + '@coca-cola.co.qa.full').toLowerCase();
                }
                
                else
                {
                    u.TimeZoneSidKey = 'Asia/Dubai';
                    u.LocaleSidKey = 'en_US';
                    u.UserName = (um.ebMobile__UserCode__c + '@coca-cola.co.ae.full').toLowerCase();
                    u.Email= (um.ebMobile__UserCode__c + '@coca-cola.co.ae.full').toLowerCase();
                }
                u.ebMobile__UserCode__c = um.ebMobile__UserCode__c ;
                u.ebMobile__IsDirect__c = um.ebMobile__IsDirect__c;
                u.ebMobile__PjpLocking__c = um.ebMobile__PJPLocking__c;
                u.CommunityNickname =  um.ebMobile__UserCode__c +  sfaSetting[0].UserEmail__c ;
                u.ParentUC__c = um.ebMobile__ParentUserCode__c;
                u.ebMobile__IsSupervisor__c = false;
                u.ebMobile__CountryCode__c=um.countrycode__c  ;
                u.ebMobile__Region__c=region.get(um.Region__c);
                u.BusinessUnit__c=businessunit.get(um.BusinessUnit__c);
                if(sfaSetting[0].LicenseHaveRole__c)
                {
                    /*Boolean isHave = false;
                    String roleId = '';
                    for(String roleName : roleNameMap.keySet())
                    {
                        if(um.ebMobile__RoleApiName__c.contains(roleName))
                        {
                            isHave = true;
                            roleId  = roleNameMap.get(roleName);
                        }
                    }
                    if(isHave == true)
                    {
                        u.UserRoleId = roleId;
                        upsertUserList.add(u);
                    }
                    else
                    {
                        u.UserRoleId = sfaSetting[0].DefaultParentRoleId__c ;
                        upsertUserList.add(u);
                    }*/
         
                    if(um.ebMobile__RoleApiName__c.contains('REPRESENTATIVE') && um.Region__c!='')
                    {
                        String bu=region.get(um.Region__c);
                        String role='REPRESENTATIVE_'+bu;
                        String rid=roleNameMap.get(role);
                        u.UserRoleId=rid;
                        u.ProfileId =  sfaSetting[0].ProfileId__c;
                        upsertUserList.add(u);
                    }
                    else if(um.ebMobile__RoleApiName__c.contains('SUPERVISOR') && um.Region__c!='')
                    {
                        String bu=region.get(um.Region__c);
                        String role='SUPERVISOR_'+bu;
                        String rid=roleNameMap.get(role);
                        u.UserRoleId=rid;
                        u.ProfileId =  sfaSetting[0].ProfileId__c;
                        upsertUserList.add(u);
                    }
                    else
                    {
                        String bu=region.get(um.Region__c);
                        String role='MANAGER_'+bu;
                        String rid=roleNameMap.get(role);
                        u.UserRoleId=rid;
                        u.ProfileId =  '00e5D000000QJodQAG';
                        upsertUserList.add(u);
                    }
                }
                else
                {
                    upsertUserList.add(u);
                }
            }
        }
      
       system.debug('upsertUserList******'+upsertUserList);
       List<Database.UpsertResult> result = Database.upsert(upsertUserList, User.ebMobile__UserCode__c  , false);
    }
Raj VakatiRaj Vakati
Can u give me an API name for ub filed refernce ? 
Raj VakatiRaj Vakati
You need to do a  test data setup as like below and then try to call u r method
 
Profile pf= [Select Id from profile where Name='System Administrator']; 
        
		
	
		
		
        String orgId=UserInfo.getOrganizationId(); 
        String dateString=String.valueof(Datetime.now()).replace(' ','').replace(':','').replace('-','') ;
        Integer RandomId=Integer.valueOf(Math.rint(Math.random()*1000000)); 
        String uniqueName=orgId+dateString+RandomId; 
        User uu=new User(firstname = 'ABC', 
                         lastName = 'XYZ', 
						  
                         email = uniqueName + '@test' + orgId + '.org', 
                         Username = uniqueName + '@test' + orgId + '.org', 
                         EmailEncodingKey = 'ISO-8859-1', 
                         Alias = uniqueName.substring(18, 23), 
                         TimeZoneSidKey = 'America/Los_Angeles', 
                         LocaleSidKey = 'en_US', 
                         LanguageLocaleKey = 'en_US', 
                         ProfileId = pf.Id
                        ); 
        
        
        insert uu;
		
		sfaSetting__c sess = new sfaSetting__c() ; 
		sess.Name ='Test'; 
		sess.EmailEncodingKey__c='ISO-8859-1';

		sess.LanguageLocaleKey__c = 'en_US'; 
		sess.ProfileId__c =pf.Id ; 
		
		insert sess ; 
		
			ebMobile__UserCode__c ec = new ebMobile__UserCode__c() ; 
		ec.Name ='Test'; 
		ec.countryCode__c='AE';
		ec.ebMobile__UserCode__c ='12312312';
		ec.ebMobile__LastName__c ='uasdgasd';
		// Add other fileds 
		
		insert ec ;

 
Sudha#aSudha#a
this is ub code please help me 
global without sharing class EbestCreateUserAndRoleBatch implements Schedulable,Database.Batchable<sObject>
{
    global final String querySQL;
    global List<UserRole> lst_roleMap = [Select id, name from UserRole];
    global List<ebMobile__PickListMaster__c> lst_plm=[SELECT ebMobile__PicklistCode__c,ebMobile__PicklistValue__c FROM ebMobile__PickListMaster__c WHERE ebMobile__ObjectName__c = 'UserMaster' AND ebMobile__FieldName__c = 'BusinessUnit__c' AND ebMobile__IsActive__c = True];
    global List<ebMobile__PickListMaster__c> lst_region=[SELECT ebMobile__PicklistCode__c,ebMobile__PicklistValue__c FROM ebMobile__PickListMaster__c WHERE ebMobile__ObjectName__c = 'UserMaster' AND ebMobile__FieldName__c = 'Region__c' AND ebMobile__IsActive__c = True];
    global List<UserSettings__c> sfaSetting = UserSettings__c.getall().values();
    global Map<String,Id> roleNameMap = new Map<String,Id>();
    global Map<String, String> businessunit = new Map<String, String>();
  global Map<String, String> region = new Map<String, String>();
    
    global EbestCreateUserAndRoleBatch()
    {
        querySQL = 'SELECT Id,ebMobile__IsActive__c,BusinessUnit__c,Region__c,ebMobile__ParentUserCode__c, ebMobile__IsDirect__c, ebMobile__IsUser__c,ebMobile__ParentRoleName__c,  ebMobile__LastName__c,ebMobile__RoleApiName__c, ebMobile__Unique__c, CountryCode__c, ebMobile__UserCode__c, Name,ebMobile__PJPLocking__c FROM ebMobile__UserMapping__c where LastModifiedDate >= Last_N_DAYS:1 ' ;//
        for(UserRole userole : lst_roleMap)
        {
            roleNameMap.put((userole.Name).touppercase(),userole.Id);
        }
        for(ebMobile__PickListMaster__c pickmast : lst_plm)
        {
            businessunit.put(pickmast.ebMobile__PicklistCode__c,(pickmast.ebMobile__PicklistValue__c).touppercase());
        }
    for(ebMobile__PickListMaster__c pick : lst_region)
        {
            region.put(pick.ebMobile__PicklistCode__c,(pick.ebMobile__PicklistValue__c).touppercase());
        }
    }
    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        return Database.getQueryLocator(querySQL);
    }

    global void execute(Database.BatchableContext BC, List<ebMobile__UserMapping__c> userMappingList)
    {
        try
        {
            if(userMappingList.size()>0)
            {
                dealUser(userMappingList);
            }
        }
        catch(Exception ex){}
    }
    
    global void dealUser(List<ebMobile__UserMapping__c> userMappingList)
    {
        List<User> upsertUserList = new List<User>();
        List<String> userCodeList = new List<String>();
        for(ebMobile__UserMapping__c um : userMappingList)
        {
            if(um.ebMobile__IsUser__c)
            {
                system.debug('usercode12:'+um.ebMobile__UserCode__c);
                userCodeList.add(um.ebMobile__UserCode__c);