• Dhananjay PV 6
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Not able to update the User email field in database eventhough the logic is correct and also debug log shows that the Email field update is done. But not able to see the same in database.

global class UserEmailupdates implements Database.Batchable<sObject>
{
    User1__c uc = User1__c.getValues('Domainuser'); 
    String inteluc = uc.Domain__c;
//    List<User> userlist=new List<User>;


    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        String query = 'SELECT name,Username,UpdatedEmail__c,email,userrole.name,profile.name From user where userrole.name = \'CRM Developer\'';
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<User> scope)
    {
        for ( User u : scope)
        {
          if(u.userrole.name == 'CRM Developer')
           {  
               if(u.username.Contains('@example.com'))  
               {       
               String str=u.username;
               String str1=u.email;
//             String username1;
               u.username=str.substringbefore('@');
               u.username=u.username.replace('=','@');
               u.Email=str1.substringbefore('@');
               u.Email=u.Email.replace('=','@');
               System.debug('Email = ' + u.Email);
               System.debug('User name = ' + u.Username);  
               }
               else
               {
               String str=u.username;
               String str1=u.Email;
               u.username=str.substringbefore('@');
               u.username=u.username+inteluc;
//             u.Username =u.DomainUser__c+inteluc;
               u.Email=str1.substringbefore('@');
               u.Email =u.Email+inteluc;
               
               System.debug('Email = ' + u.Email);
               System.debug('User name = ' + u.Username);     
               }
           }
           
        }
        update scope;
        System.debug('Scope is= '+ Scope);
    }  
    global void finish(Database.BatchableContext BC)
    {
    }
}

Below is the debug log details
global class UserEmailupdates implements Database.Batchable<sObject>
{
    User1__c uc = User1__c.getValues('Domainuser'); 
    String inteluc = uc.Domain__c;
//    List<User> userlist=new List<User>;


    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        String query = 'SELECT name,Username,UpdatedEmail__c,email,userrole.name,profile.name From user where userrole.name = \'CRM Developer\'';
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<User> scope)
    {
        for ( User u : scope)
        {
          if(u.userrole.name == 'CRM Developer')
           {  
               if(u.username.Contains('@example.com'))  
               {       
               String str=u.username;
               String str1=u.email;
//             String username1;
               u.username=str.substringbefore('@');
               u.username=u.username.replace('=','@');
               u.Email=str1.substringbefore('@');
               u.Email=u.Email.replace('=','@');
               System.debug('Email = ' + u.Email);
               System.debug('User name = ' + u.Username);  
               }
               else
               {
               String str=u.username;
               String str1=u.Email;
               u.username=str.substringbefore('@');
               u.username=u.username+inteluc;
//             u.Username =u.DomainUser__c+inteluc;
               u.Email=str1.substringbefore('@');
               u.Email =u.Email+inteluc;
               
               System.debug('Email = ' + u.Email);
               System.debug('User name = ' + u.Username);     
               }
           }
           
        }
        update scope;
        System.debug('Scope is= '+ Scope);
    }  
    global void finish(Database.BatchableContext BC)
    {
    }
}


Debug log info is attached.

Input data :

User Name : suri101070@gmail.com
Email : suri101070@gmail.com

Output expecting :

User name : suri101070@intel.com
Email : suri101070@intel.com

But here can see the username getting updated in database but email field is not getting updated. Is Salesforce is enforcing any rule/restriction and preventing the Email field Update?Debug log info
Not able to update the User email field in database eventhough the logic is correct and also debug log shows that the Email field update is done. But not able to see the same in database.

global class UserEmailupdates implements Database.Batchable<sObject>
{
    User1__c uc = User1__c.getValues('Domainuser'); 
    String inteluc = uc.Domain__c;
//    List<User> userlist=new List<User>;


    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        String query = 'SELECT name,Username,UpdatedEmail__c,email,userrole.name,profile.name From user where userrole.name = \'CRM Developer\'';
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<User> scope)
    {
        for ( User u : scope)
        {
          if(u.userrole.name == 'CRM Developer')
           {  
               if(u.username.Contains('@example.com'))  
               {       
               String str=u.username;
               String str1=u.email;
//             String username1;
               u.username=str.substringbefore('@');
               u.username=u.username.replace('=','@');
               u.Email=str1.substringbefore('@');
               u.Email=u.Email.replace('=','@');
               System.debug('Email = ' + u.Email);
               System.debug('User name = ' + u.Username);  
               }
               else
               {
               String str=u.username;
               String str1=u.Email;
               u.username=str.substringbefore('@');
               u.username=u.username+inteluc;
//             u.Username =u.DomainUser__c+inteluc;
               u.Email=str1.substringbefore('@');
               u.Email =u.Email+inteluc;
               
               System.debug('Email = ' + u.Email);
               System.debug('User name = ' + u.Username);     
               }
           }
           
        }
        update scope;
        System.debug('Scope is= '+ Scope);
    }  
    global void finish(Database.BatchableContext BC)
    {
    }
}

Below is the debug log details
global class UserEmailupdates implements Database.Batchable<sObject>
{
    User1__c uc = User1__c.getValues('Domainuser'); 
    String inteluc = uc.Domain__c;
//    List<User> userlist=new List<User>;


    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        String query = 'SELECT name,Username,UpdatedEmail__c,email,userrole.name,profile.name From user where userrole.name = \'CRM Developer\'';
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<User> scope)
    {
        for ( User u : scope)
        {
          if(u.userrole.name == 'CRM Developer')
           {  
               if(u.username.Contains('@example.com'))  
               {       
               String str=u.username;
               String str1=u.email;
//             String username1;
               u.username=str.substringbefore('@');
               u.username=u.username.replace('=','@');
               u.Email=str1.substringbefore('@');
               u.Email=u.Email.replace('=','@');
               System.debug('Email = ' + u.Email);
               System.debug('User name = ' + u.Username);  
               }
               else
               {
               String str=u.username;
               String str1=u.Email;
               u.username=str.substringbefore('@');
               u.username=u.username+inteluc;
//             u.Username =u.DomainUser__c+inteluc;
               u.Email=str1.substringbefore('@');
               u.Email =u.Email+inteluc;
               
               System.debug('Email = ' + u.Email);
               System.debug('User name = ' + u.Username);     
               }
           }
           
        }
        update scope;
        System.debug('Scope is= '+ Scope);
    }  
    global void finish(Database.BatchableContext BC)
    {
    }
}


Debug log info is attached.

Input data :

User Name : suri101070@gmail.com
Email : suri101070@gmail.com

Output expecting :

User name : suri101070@intel.com
Email : suri101070@intel.com

But here can see the username getting updated in database but email field is not getting updated. Is Salesforce is enforcing any rule/restriction and preventing the Email field Update?Debug log info