• Sudha#a
  • NEWBIE
  • 20 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 14
    Questions
  • 21
    Replies
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);
                User u = new User();
                u.IsActive=um.ebMobile__IsActive__c;
                u.FirstName=um.ebMobile__FirstName__c.toLowerCase();
                //u.CommunityNickname=um.ebMobile__UserCode__c.toLowerCase();
                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);
    }

     //Schedulable exceute
    global void execute(SchedulableContext ctx)
    {
        EbestCreateUserAndRoleBatch batch = new EbestCreateUserAndRoleBatch();
        Database.executeBatch(batch, 10);
    }

    global void finish(Database.BatchableContext BC)
    {
        /*if(!Test.isRunningTest())
        {
            EbestUpdateUserManagerBatch batch = new EbestUpdateUserManagerBatch();
            Database.executeBatch(batch, 1);  
        }*/
    }
}
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);
    }
View | Download | DeleteAGL AdminApiUnknownSerialBatchApexRangeChunkHandlerSuccess1211,12611/08 00:11:36
View | Download | DeleteAGL AdminApiUnknownBatch ApexSuccess1131,12611/08 00:11:36
View | Download | DeleteAGL AdminApiUnknownSerialBatchApexRangeChunkHandlerSuccess7854811/08 00:11:36
View | Download | DeleteAGL AdminApiUnknownSerialBatchApexRangeChunkHandlerSuccess4054911/08 00:11:36
View | Download | DeleteAGL AdminApiUnknownBatch ApexSuccess871,56711/08 00:11:35
global class AutocreatedRegHandler1428339965041 implements Auth.SamlJitHandler {
  private class JitException extends Exception{}
  private void handleUser(boolean create, User u, Map<String, String> attributes,
    String federationIdentifier, boolean isStandard) {
    if(create && attributes.containsKey('User.Username')) {
      u.Username = attributes.get('User.Username');
    }
    if(create) {
      if(attributes.containsKey('User.FederationIdentifier')) {
        u.FederationIdentifier = attributes.get('User.FederationIdentifier');
      } else {
        u.FederationIdentifier = federationIdentifier;
      }
    }
    if(attributes.containsKey('User.ProfileId')) {
      String profileId = attributes.get('User.ProfileId');
      Profile p = [SELECT Id FROM Profile WHERE Id=:profileId];
      u.ProfileId = p.Id;
    }
    if(attributes.containsKey('User.UserRoleId')) {
      String userRole = attributes.get('User.UserRoleId');
      UserRole r = [SELECT Id FROM UserRole WHERE Id=:userRole];
      u.UserRoleId = r.Id;
    }
    if(attributes.containsKey('User.Phone')) {
      u.Phone = attributes.get('User.Phone');
    }
    if(attributes.containsKey('User.Email')) {
      u.Email = attributes.get('User.Email');
    }
    if(attributes.containsKey('User.FirstName')) {
      u.FirstName = attributes.get('User.FirstName');
    }
    if(attributes.containsKey('User.LastName')) {
      u.LastName = attributes.get('User.LastName');
    }
    if(attributes.containsKey('User.Title')) {
      u.Title = attributes.get('User.Title');
    }
    if(attributes.containsKey('User.CompanyName')) {
      u.CompanyName = attributes.get('User.CompanyName');
    }
    if(attributes.containsKey('User.AboutMe')) {
      u.AboutMe = attributes.get('User.AboutMe');
    }
    if(attributes.containsKey('User.Street')) {
      u.Street = attributes.get('User.Street');
    }
    if(attributes.containsKey('User.State')) {
      u.State = attributes.get('User.State');
    }
    if(attributes.containsKey('User.City')) {
      u.City = attributes.get('User.City');
    }
    if(attributes.containsKey('User.Zip')) {
      u.PostalCode = attributes.get('User.Zip');
    }
    if(attributes.containsKey('User.Country')) {
      u.Country = attributes.get('User.Country');
    }
    if(attributes.containsKey('User.CallCenter')) {
      u.CallCenterId = attributes.get('User.CallCenter');
    }
    if(attributes.containsKey('User.Manager')) {
      u.ManagerId = attributes.get('User.Manager');
    }
    if(attributes.containsKey('User.MobilePhone')) {
      u.MobilePhone = attributes.get('User.MobilePhone');
    }
    if(attributes.containsKey('User.DelegatedApproverId')) {
      u.DelegatedApproverId = attributes.get('User.DelegatedApproverId');
    }
    if(attributes.containsKey('User.Department')) {
      u.Department = attributes.get('User.Department');
    }
    if(attributes.containsKey('User.Division')) {
      u.Division = attributes.get('User.Division');
    }
    if(attributes.containsKey('User.EmployeeNumber')) {
      u.EmployeeNumber = attributes.get('User.EmployeeNumber');
    }
    if(attributes.containsKey('User.Extension')) {
      u.Extension = attributes.get('User.Extension');
    }
    if(attributes.containsKey('User.Fax')) {
      u.Fax = attributes.get('User.Fax');
    }
    if(attributes.containsKey('User.CommunityNickname')) {
      u.CommunityNickname = attributes.get('User.CommunityNickname');
    }
    if(attributes.containsKey('User.IsActive')) {
      String IsActiveVal = attributes.get('User.IsActive');
      u.IsActive = '1'.equals(IsActiveVal) || Boolean.valueOf(IsActiveVal);
    }
    if(attributes.containsKey('User.ReceivesAdminInfoEmails')) {
      String ReceivesAdminInfoEmailsVal = attributes.get('User.ReceivesAdminInfoEmails');
      u.ReceivesAdminInfoEmails = '1'.equals(ReceivesAdminInfoEmailsVal) || Boolean.valueOf(ReceivesAdminInfoEmailsVal);
    }
    if(attributes.containsKey('User.ReceivesInfoEmails')) {
      String ReceivesInfoEmailsVal = attributes.get('User.ReceivesInfoEmails');
      u.ReceivesInfoEmails = '1'.equals(ReceivesInfoEmailsVal) || Boolean.valueOf(ReceivesInfoEmailsVal);
    }
    if(attributes.containsKey('User.ForecastEnabled')) {
      String ForecastEnabledVal = attributes.get('User.ForecastEnabled');
      u.ForecastEnabled = '1'.equals(ForecastEnabledVal) || Boolean.valueOf(ForecastEnabledVal);
    }
    String uid = UserInfo.getUserId();
    User currentUser = 
      [SELECT LocaleSidKey, LanguageLocaleKey, TimeZoneSidKey, EmailEncodingKey FROM User WHERE Id=:uid];
    if(attributes.containsKey('User.LocaleSidKey')) {
      u.LocaleSidKey = attributes.get('User.LocaleSidKey');
    } else if(create) {
      u.LocaleSidKey = currentUser.LocaleSidKey;
    }
    if(attributes.containsKey('User.LanguageLocaleKey')) {
      u.LanguageLocaleKey = attributes.get('User.LanguageLocaleKey');
    } else if(create) {
      u.LanguageLocaleKey = currentUser.LanguageLocaleKey;
    }
    if(attributes.containsKey('User.Alias')) {
      u.Alias = attributes.get('User.Alias');
    } else if(create) {
      String alias = '';
      if(u.FirstName == null) {
        alias = u.LastName;
      } else {
        alias = u.FirstName.charAt(0) + u.LastName;
      }
      if(alias.length() > 5) {
        alias = alias.substring(0, 5);
      }
      u.Alias = alias;
    }
    if(attributes.containsKey('User.TimeZoneSidKey')) {
      u.TimeZoneSidKey = attributes.get('User.TimeZoneSidKey');
    } else if(create) {
      u.TimeZoneSidKey = currentUser.TimeZoneSidKey;
    }
    if(attributes.containsKey('User.EmailEncodingKey')) {
      u.EmailEncodingKey = attributes.get('User.EmailEncodingKey');
    } else if(create) {
      u.EmailEncodingKey = currentUser.EmailEncodingKey;
    }

//Handle custom fields here

    if(!create) {
      update(u);
    }
  }

  private void handleContact(boolean create, String accountId, User u, Map<String, String> attributes) {
    Contact c;
    boolean newContact = false;
    if(create) {
      if(attributes.containsKey('User.Contact')) {
      String contact = attributes.get('User.Contact');
        c = [SELECT Id, AccountId FROM Contact WHERE Id=:contact];
        u.ContactId = contact;
      } else {
        c = new Contact();
        newContact = true;
      }
    } else {
      if(attributes.containsKey('User.Contact')) {
        String contact = attributes.get('User.Contact');
        c = [SELECT Id, AccountId FROM Contact WHERE Id=:contact];
        if(u.ContactId != c.Id) {
          throw new JitException('Cannot change User.ContactId');
        }
      } else {
        String contact = u.ContactId;
        c = [SELECT Id, AccountId FROM Contact WHERE Id=:contact];
      }
    }
    if(!newContact && c.AccountId != accountId) {
      throw new JitException('Mismatched account: ' + c.AccountId + ', ' + accountId);
    }

    if(attributes.containsKey('Contact.Email')) {
      c.Email = attributes.get('Contact.Email');
    }
    if(attributes.containsKey('Contact.FirstName')) {
      c.FirstName = attributes.get('Contact.FirstName');
    }
    if(attributes.containsKey('Contact.LastName')) {
      c.LastName = attributes.get('Contact.LastName');
    }
    if(attributes.containsKey('Contact.Phone')) {
      c.Phone = attributes.get('Contact.Phone');
    }
    if(attributes.containsKey('Contact.MailingStreet')) {
      c.MailingStreet = attributes.get('Contact.MailingStreet');
    }
    if(attributes.containsKey('Contact.MailingCity')) {
      c.MailingCity = attributes.get('Contact.MailingCity');
    }
    if(attributes.containsKey('Contact.MailingState')) {
      c.MailingState = attributes.get('Contact.MailingState');
    }
    if(attributes.containsKey('Contact.MailingCountry')) {
      c.MailingCountry = attributes.get('Contact.MailingCountry');
    }
    if(attributes.containsKey('Contact.MailingPostalCode')) {
      c.MailingPostalCode = attributes.get('Contact.MailingPostalCode');
    }
    if(attributes.containsKey('Contact.OtherStreet')) {
      c.OtherStreet = attributes.get('Contact.OtherStreet');
    }
    if(attributes.containsKey('Contact.OtherCity')) {
      c.OtherCity = attributes.get('Contact.OtherCity');
    }
    if(attributes.containsKey('Contact.OtherState')) {
      c.OtherState = attributes.get('Contact.OtherState');
    }
    if(attributes.containsKey('Contact.OtherCountry')) {
      c.OtherCountry = attributes.get('Contact.OtherCountry');
    }
    if(attributes.containsKey('Contact.OtherPostalCode')) {
      c.OtherPostalCode = attributes.get('Contact.OtherPostalCode');
    }
    if(attributes.containsKey('Contact.AssistantPhone')) {
      c.AssistantPhone = attributes.get('Contact.AssistantPhone');
    }
    if(attributes.containsKey('Contact.Department')) {
      c.Department = attributes.get('Contact.Department');
    }
    if(attributes.containsKey('Contact.Description')) {
      c.Description = attributes.get('Contact.Description');
    }
    if(attributes.containsKey('Contact.Fax')) {
      c.Fax = attributes.get('Contact.Fax');
    }
    if(attributes.containsKey('Contact.HomePhone')) {
      c.HomePhone = attributes.get('Contact.HomePhone');
    }
    if(attributes.containsKey('Contact.MobilePhone')) {
      c.MobilePhone = attributes.get('Contact.MobilePhone');
    }
    if(attributes.containsKey('Contact.OtherPhone')) {
      c.OtherPhone = attributes.get('Contact.OtherPhone');
    }
    if(attributes.containsKey('Contact.Title')) {
      c.Title = attributes.get('Contact.Title');
    }
    if(attributes.containsKey('Contact.Salutation')) {
      c.Salutation = attributes.get('Contact.Salutation');
    }
    if(attributes.containsKey('Contact.LeadSource')) {
      c.LeadSource = attributes.get('Contact.LeadSource');
    }
    if(attributes.containsKey('Contact.DoNotCall')) {
      String DoNotCallVal = attributes.get('Contact.DoNotCall');
      c.DoNotCall = '1'.equals(DoNotCallVal) || Boolean.valueOf(DoNotCallVal);
    }
    if(attributes.containsKey('Contact.HasOptedOutOfEmail')) {
      String HasOptedOutOfEmailVal = attributes.get('Contact.HasOptedOutOfEmail');
      c.HasOptedOutOfEmail = '1'.equals(HasOptedOutOfEmailVal) || Boolean.valueOf(HasOptedOutOfEmailVal);
    }
    if(attributes.containsKey('Contact.HasOptedOutOfFax')) {
      String HasOptedOutOfFaxVal = attributes.get('Contact.HasOptedOutOfFax');
      c.HasOptedOutOfFax = '1'.equals(HasOptedOutOfFaxVal) || Boolean.valueOf(HasOptedOutOfFaxVal);
    }
    if(attributes.containsKey('Contact.Owner')) {
      c.OwnerId = attributes.get('Contact.Owner');
    }
    if(attributes.containsKey('Contact.AssistantName')) {
      c.AssistantName = attributes.get('Contact.AssistantName');
    }
    if(attributes.containsKey('Contact.Birthdate')) {
      c.Birthdate = Date.valueOf(attributes.get('Contact.Birthdate'));
    }
    if(newContact) {
      c.AccountId = accountId;
      insert(c);
      u.ContactId = c.Id;
    } else {
      update(c);
    }
  }

  private String handleAccount(boolean create, User u, Map<String, String> attributes) {
    Account a;
    boolean newAccount = false;
    if(create) {
      if(attributes.containsKey('User.Account')) {
        String account = attributes.get('User.Account');
        a = [SELECT Id FROM Account WHERE Id=:account];
      } else {
        if(attributes.containsKey('User.Contact')) {
          String contact = attributes.get('User.Contact');
          Contact c = [SELECT AccountId FROM Contact WHERE Id=:contact];
          String account = c.AccountId;
          a = [SELECT Id FROM Account WHERE Id=:account];
        } else {
          a = new Account();
          newAccount = true;
        }
      }
    } else {
      if(attributes.containsKey('User.Account')) {
      String account = attributes.get('User.Account');
        a = [SELECT Id FROM Account WHERE Id=:account];
      } else {
        if(attributes.containsKey('User.Contact')) {
          String contact = attributes.get('User.Contact');
          Contact c = [SELECT Id, AccountId FROM Contact WHERE Id=:contact];
          if(u.ContactId != c.Id) {
            throw new JitException('Cannot change User.ContactId');
          }
          String account = c.AccountId;
          a = [SELECT Id FROM Account WHERE Id=:account];
        } else {
          throw new JitException('Could not find account');
        }
      }
    }
    if(attributes.containsKey('Account.Name')) {
      a.Name = attributes.get('Account.Name');
    }
    if(attributes.containsKey('Account.AccountNumber')) {
      a.AccountNumber = attributes.get('Account.AccountNumber');
    }
    if(attributes.containsKey('Account.Owner')) {
      a.OwnerId = attributes.get('Account.Owner');
    }
    if(attributes.containsKey('Account.BillingStreet')) {
      a.BillingStreet = attributes.get('Account.BillingStreet');
    }
    if(attributes.containsKey('Account.BillingCity')) {
      a.BillingCity = attributes.get('Account.BillingCity');
    }
    if(attributes.containsKey('Account.BillingState')) {
      a.BillingState = attributes.get('Account.BillingState');
    }
    if(attributes.containsKey('Account.BillingCountry')) {
      a.BillingCountry = attributes.get('Account.BillingCountry');
    }
    if(attributes.containsKey('Account.BillingPostalCode')) {
      a.BillingPostalCode = attributes.get('Account.BillingPostalCode');
    }
    if(attributes.containsKey('Account.AnnualRevenue')) {
      a.AnnualRevenue = Integer.valueOf(attributes.get('Account.AnnualRevenue'));
    }
    if(attributes.containsKey('Account.Description')) {
      a.Description = attributes.get('Account.Description');
    }
    if(attributes.containsKey('Account.Fax')) {
      a.Fax = attributes.get('Account.Fax');
    }
    if(attributes.containsKey('Account.NumberOfEmployees')) {
      a.NumberOfEmployees = Integer.valueOf(attributes.get('Account.NumberOfEmployees'));
    }
    if(attributes.containsKey('Account.Phone')) {
      a.Phone = attributes.get('Account.Phone');
    }
    if(attributes.containsKey('Account.ShippingStreet')) {
      a.ShippingStreet = attributes.get('Account.ShippingStreet');
    }
    if(attributes.containsKey('Account.ShippingCity')) {
      a.ShippingCity = attributes.get('Account.ShippingCity');
    }
    if(attributes.containsKey('Account.ShippingState')) {
      a.ShippingState = attributes.get('Account.ShippingState');
    }
    if(attributes.containsKey('Account.ShippingCountry')) {
      a.ShippingCountry = attributes.get('Account.ShippingCountry');
    }
    if(attributes.containsKey('Account.ShippingPostalCode')) {
      a.ShippingPostalCode = attributes.get('Account.ShippingPostalCode');
    }
    if(attributes.containsKey('Account.Sic')) {
      a.Sic = attributes.get('Account.Sic');
    }
    if(attributes.containsKey('Account.TickerSymbol')) {
      a.TickerSymbol = attributes.get('Account.TickerSymbol');
    }
    if(attributes.containsKey('Account.Website')) {
      a.Website = attributes.get('Account.Website');
    }
    if(attributes.containsKey('Account.Industry')) {
      a.Industry = attributes.get('Account.Industry');
    }
    if(attributes.containsKey('Account.Ownership')) {
      a.Ownership = attributes.get('Account.Ownership');
    }
    if(attributes.containsKey('Account.Rating')) {
      a.Rating = attributes.get('Account.Rating');
    }
    if(newAccount) {
      insert(a);
    } else {
      update(a);
    }
    return a.Id;
  }

  private void handleJit(boolean create, User u, Id samlSsoProviderId, Id communityId, Id portalId,
    String federationIdentifier, Map<String, String> attributes, String assertion) {
    if(communityId != null || portalId != null) {
      String account = handleAccount(create, u, attributes);
      handleContact(create, account, u, attributes);
      handleUser(create, u, attributes, federationIdentifier, false);
    } else {
      handleUser(create, u, attributes, federationIdentifier, true);
    }
  }

  
The report shows the different dimensions. But what we would really like to know is:
 Here is an example of a report we would like to snapshot at the end of every month.

A) How many requests were opened each month
B) How many requests were closed each month
C) How many requests were still open at month end (Total opened – total closed)
 
These metrics would be useful for each dimension, I.e. Priority, department, service, category, staff, etc.
 
trigger skill_mappingTrigger on Case (before insert, after insert, before update, after update) {

    CaseTriggerHandler handler = new CaseTriggerHandler();
    
    if(Trigger.isBefore && Trigger.isInsert) {
        handler.onBeforeInsert(Trigger.old, Trigger.new, Trigger.oldMap, Trigger.newMap);    
    }
    if(Trigger.isAfter && Trigger.isInsert) {
        handler.onAfterInsert(Trigger.old, Trigger.new, Trigger.oldMap, Trigger.newMap);    
    }
    if(Trigger.isBefore && Trigger.isUpdate) {
        handler.onBeforeUpdate(Trigger.old, Trigger.new, Trigger.oldMap, Trigger.newMap);    
    }
    if(Trigger.isAfter && Trigger.isUpdate) {
        handler.onAfterUpdate(Trigger.old, Trigger.new, Trigger.oldMap, Trigger.newMap);    
    }
             
global class Schedule_SubscriptionCMRRRollup implements Schedulable{

    public static String CRON = '0 00 00 * * ?';  //Every Day at Midnight 

    global static String scheduleMe() {
        Schedule_SubscriptionCMRRRollup SC = new Schedule_SubscriptionCMRRRollup(); 
        return System.schedule('Subscription CMRR Rollup Job', CRON, SC);
    }

    global void execute(SchedulableContext sc) {

        Batch_SubscriptionCMRRRollup batch = new Batch_SubscriptionCMRRRollup ();// create Object in Batch class//
        Database.executeBatch(batch,50);           
    }
}
global  class Batch_SubscriptionCMRRRollup implements Database.Batchable<SObject>{

global Database.QueryLocator start(Database.BatchableContext context) {
    //get all the billing accounts and the related subscriptions
    return Database.getQueryLocator([Select Id,Today_s_MRR__c,(Select Id,Zuora__MRR__c,Zuora__Status__c,Zuora__ServiceActivationDate__c from Zuora__Subscriptions__r) from Zuora__CustomerAccount__c]);
}

global void execute(Database.BatchableContext context, List<Zuora__CustomerAccount__c> listOfBillingAccounts) {

    //Iterate through all the billing accounts
    for(Zuora__CustomerAccount__c iteratingAccount: listOfBillingAccounts){
    
        //Iterate through all the subscriptions
        for(Zuora__Subscription__c iteratingSubscription : iteratingAccount.Zuora__Subscriptions__r){
            
            //add only those active subscriptions
            if((iteratingSubscription.Zuora__Status__c == 'Active' || 
                iteratingSubscription.Zuora__Status__c=='active') &&
                iteratingSubscription.Zuora__ServiceActivationDate__c <=  Date.Today() &&
                iteratingSubscription.Zuora__MRR__c != NULL){
                   iteratingAccount.Today_s_MRR__c += iteratingSubscription.Zuora__MRR__c;
            }
        }
    }
    
    update listOfBillingAccounts;
}

global void finish(Database.BatchableContext context) {}}
Setup a new fields “Today’s MRR” and “CMMR” on the Account object. These fields should be based on a roll-up of the same fields at the Billing Account level.
 
4. Create an Apex job that:
4.1 Loops through all Billing Accounts and rolls-up Today’s MRR to the Billing Account Level.
4.2 Loops through all Accounts and rolls-up Today’s MRR and CMMT to the Account Level.
 
This job should run once a day during non-business hours.
 
The new fields should take currencies into account and report the numbers in USD. For example, if the Subscription was booked in EUR, the calculation should convert the amounts to the base currency which is USD
public class Batch_SubscriptionCMRRRollup implements Database.Batchable<SObject>{

public Database.QueryLocator start(Database.BatchableContext context) {

    return Database.getQueryLocator([Select Id,Today_s_MRR__c,(Select Id,Zuora__MRR__c from Zuora__Subscriptions__r) from Zuora__CustomerAccount__c]);
}

public void execute(Database.BatchableContext context, List<Zuora__CustomerAccount__c> scope) {

System.debug('@@scope'+scope);
for(Zuora__CustomerAccount__c acc: scope){
    for(Zuora__Subscription__c z: acc.Zuora__Subscriptions__r){
        acc.Today_s_MRR__c += z.Zuora__MRR__c;
    }
}

}

public void finish(Database.BatchableContext context) {}
}

trigger SubscriptionCMRRRollup on Zuora__Subscription__c (after insert, after update, after delete)
{
    
    Set<Id> BillingAccId = new Set<Id>();
    List<Zuora__CustomerAccount__c> BillingAccList = new List<Zuora__CustomerAccount__c>();
    
    if(Trigger.isInsert){
        for(Zuora__Subscription__c s: Trigger.new)
            BillingAccId.add(s.Zuora__CustomerAccount__c);
    }
    if(Trigger.isUpdate || Trigger.isDelete){
        for(Zuora__Subscription__c s: Trigger.old)
            BillingAccId.add(s.Zuora__CustomerAccount__c);
    }
    Map<id,Zuora__CustomerAccount__c> BillingAccMap = new Map<id,Zuora__CustomerAccount__c>([select id, Today_s_MRR__c from Zuora__CustomerAccount__c where id IN :BillingAccId]);
    
    for(Zuora__CustomerAccount__c sub:[Select Id,Today_s_MRR__c,( Select Id,Zuora__MRR__c from Zuora__Subscriptions__r) from Zuora__CustomerAccount__c where Id IN :BillingAccId]){
        for(Zuora__Subscription__c z: sub.Zuora__Subscriptions__r){
            BillingAccMap.get(sub.Id).Today_s_MRR__c += z.Zuora__MRR__c;
            BillingAccList.add(BillingAccMap.get(sub.Id));
        }
    }
    update BillingAccList;
}
 
public class EmailAttachmentController {
    public Id caseId { get;set;}
    public List<Attachment>AttachmentCollection
    {
        get
        {
            system.debug('caseID:- '+  caseId);
            List<Case> CasesCollection = new List<Case>();
            CasesCollection = [SELECT id, Service_Interruption__c FROM CASE WHERE id = :caseId];
            if(CasesCollection.size()>0){
                AttachmentCollection = [SELECT Body, parentID,ContentType, Name from Attachment WHERE ParentId =: CasesCollection[0].Service_Interruption__c];
            }
            return AttachmentCollection; 
        }
        set;
    }
    
    
    public EmailAttachmentController()
    {
        //inputId = '%' + 500 + '%';
        
    }
}
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);
    }

I need to have a trigger on Accounts but getting stuck up in governor limits

As having the following scenario:
Parent Account has a related list that holds a list of child accounts for the respective parent account.
If a field named PortType is updated on Parent account, then this field is needed to be updated on all corresponding child accounts.

As I thought of creating a MAP (ID, Account), so as to fetch and update account from the MAP and then update them collecting in a list at once, but that did not work as Accounts records are too much that MAP is not able to hold and getting an error as MAP limit exceeds.

Getting following issues:

  1. Recursive update loop, as a child accounts are getting and a trigger is on account update.
  2. Account are many many, even if I think to take all account on a Map at once and execute, Map limit is getting exceeded as there are more then 500000 accounts in the ORG.

Please guide me how to process such bulk operations...

Hi ,

i am getting error from managed package apex trigger. So i am uanble to save my record. How to stop the trigger form managed package

Regards,
Vinothini
This issue involves 4 objects.
  • Insertions and child object called Insertion Details (records)
  • Publisher Accounts
  • Specs
On the Insertion parent record - a user needs to identify a publisher account....

User-added image


On the Insertions Details Record the User Needs to Specify Actual Dimensions:

User-added image


What I'm looking to do is create a dynamic way so if the user selects from a picklist on the insertion child record any of the columns below (double truck actual, full page actual, junior page, etc as shown in screenshot below), then a second field will auto populate the specs data for that specific publisher and if there is no data referenceable then the user can input some value.

Is this possible?


User-added image

 
Hello,

I am working on an apex batchable class that processes invoice records by creating new account and opportunity records based on the invoices. The class then deletes the processed invoices. The process is started by clicking a custom button (Process Invoices) added to the list view of invoices.

The problem that I am experiencing is that after pressing the process invoices button the class seems to process the first batch of records (batch size of 20), but never hits the second (or any other) instances of the batchable class' execute method.

The logs in the developer console show that operation "SerialBatchApexRangeChunkHandler" has a status of "Internal Salesforce.com Error". Unfortunately I cannot share code for security reasons, but if anyone has any experience with this error, and information regarding a fix I would appreciate the insight.
HI Experts,

Can i get any help in doing some HTML code on apex messages,its so simple but some how am not able to get it, below apex message i wanted to be in a table format this is what am trying,but not able crack,according to my code i cannot use any Email Templates,any help greatly appreciated
emailBody += <html><body> Hi ,<br/><br/><h4>Automated mail for the Field updates -</h4><table style="width:100%">+'\N'+ type + ' : \N '+'</table></body></html>';
                               //for new fields
                             for(Field f : bkupnewFields.values()) 
                {
                    emailBody += f.apiName + ' with datatype '+f.dataType+' is newly created.\n';

 /*** Sending Email ***/
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
 List<String> emails =  new List<String>();emails.addAll(system.label.Dev_Admin.split(';'));
  mail.setToAddresses(emails);
        //mail.setToAddresses(new List<String>{.split(';')});
              mail.setSubject('Fields Update');
             mail.setPlainTextBody(emailBody);
             update objectInfoMap.values();
             Messaging.sendEmail(new Messaging.SingleEmailMessage[]{mail});



Thans in advance!
The report shows the different dimensions. But what we would really like to know is:
 Here is an example of a report we would like to snapshot at the end of every month.

A) How many requests were opened each month
B) How many requests were closed each month
C) How many requests were still open at month end (Total opened – total closed)
 
These metrics would be useful for each dimension, I.e. Priority, department, service, category, staff, etc.
 
Hello everybody !
Someone could help me to resolve this problem please ?
 
global class Schedule_SubscriptionCMRRRollup implements Schedulable{

    public static String CRON = '0 00 00 * * ?';  //Every Day at Midnight 

    global static String scheduleMe() {
        Schedule_SubscriptionCMRRRollup SC = new Schedule_SubscriptionCMRRRollup(); 
        return System.schedule('Subscription CMRR Rollup Job', CRON, SC);
    }

    global void execute(SchedulableContext sc) {

        Batch_SubscriptionCMRRRollup batch = new Batch_SubscriptionCMRRRollup ();// create Object in Batch class//
        Database.executeBatch(batch,50);           
    }
}
global  class Batch_SubscriptionCMRRRollup implements Database.Batchable<SObject>{

global Database.QueryLocator start(Database.BatchableContext context) {
    //get all the billing accounts and the related subscriptions
    return Database.getQueryLocator([Select Id,Today_s_MRR__c,(Select Id,Zuora__MRR__c,Zuora__Status__c,Zuora__ServiceActivationDate__c from Zuora__Subscriptions__r) from Zuora__CustomerAccount__c]);
}

global void execute(Database.BatchableContext context, List<Zuora__CustomerAccount__c> listOfBillingAccounts) {

    //Iterate through all the billing accounts
    for(Zuora__CustomerAccount__c iteratingAccount: listOfBillingAccounts){
    
        //Iterate through all the subscriptions
        for(Zuora__Subscription__c iteratingSubscription : iteratingAccount.Zuora__Subscriptions__r){
            
            //add only those active subscriptions
            if((iteratingSubscription.Zuora__Status__c == 'Active' || 
                iteratingSubscription.Zuora__Status__c=='active') &&
                iteratingSubscription.Zuora__ServiceActivationDate__c <=  Date.Today() &&
                iteratingSubscription.Zuora__MRR__c != NULL){
                   iteratingAccount.Today_s_MRR__c += iteratingSubscription.Zuora__MRR__c;
            }
        }
    }
    
    update listOfBillingAccounts;
}

global void finish(Database.BatchableContext context) {}}
Setup a new fields “Today’s MRR” and “CMMR” on the Account object. These fields should be based on a roll-up of the same fields at the Billing Account level.
 
4. Create an Apex job that:
4.1 Loops through all Billing Accounts and rolls-up Today’s MRR to the Billing Account Level.
4.2 Loops through all Accounts and rolls-up Today’s MRR and CMMT to the Account Level.
 
This job should run once a day during non-business hours.
 
The new fields should take currencies into account and report the numbers in USD. For example, if the Subscription was booked in EUR, the calculation should convert the amounts to the base currency which is USD
public class Batch_SubscriptionCMRRRollup implements Database.Batchable<SObject>{

public Database.QueryLocator start(Database.BatchableContext context) {

    return Database.getQueryLocator([Select Id,Today_s_MRR__c,(Select Id,Zuora__MRR__c from Zuora__Subscriptions__r) from Zuora__CustomerAccount__c]);
}

public void execute(Database.BatchableContext context, List<Zuora__CustomerAccount__c> scope) {

System.debug('@@scope'+scope);
for(Zuora__CustomerAccount__c acc: scope){
    for(Zuora__Subscription__c z: acc.Zuora__Subscriptions__r){
        acc.Today_s_MRR__c += z.Zuora__MRR__c;
    }
}

}

public void finish(Database.BatchableContext context) {}
}
public class EmailAttachmentController {
    public Id caseId { get;set;}
    public List<Attachment>AttachmentCollection
    {
        get
        {
            system.debug('caseID:- '+  caseId);
            List<Case> CasesCollection = new List<Case>();
            CasesCollection = [SELECT id, Service_Interruption__c FROM CASE WHERE id = :caseId];
            if(CasesCollection.size()>0){
                AttachmentCollection = [SELECT Body, parentID,ContentType, Name from Attachment WHERE ParentId =: CasesCollection[0].Service_Interruption__c];
            }
            return AttachmentCollection; 
        }
        set;
    }
    
    
    public EmailAttachmentController()
    {
        //inputId = '%' + 500 + '%';
        
    }
}