You need to sign in to do that
Don't have an account?
Alex Kirby
Dynamically changing inactive account owners.
HI All,
I have put a small schedulable class together to run in the evenings to identify accounts with inactive owners and change them to a holding owner until they are ready to be allocated again.
The reason they need to be with an active owner is due to us pushing in data from external systems over night to keep out accounts update.
Here is the class:
This seems to work fine the issue I am having is I am only able to cover 75% of the class due to the "inactive" owner...
Here is my test class:
Any ideas on how I can get round this ?
Thanks
I have put a small schedulable class together to run in the evenings to identify accounts with inactive owners and change them to a holding owner until they are ready to be allocated again.
The reason they need to be with an active owner is due to us pushing in data from external systems over night to keep out accounts update.
Here is the class:
global class inactiveAccountOwnerChange implements schedulable { global void execute(SchedulableContext SC) { id SFUser; List <Account> accountToUpdate = [Select Id, owner.Isactive from Account where owner.isactive = False]; List <User> SFU = [Select id from user where name = 'Salesforce Unallocated']; SFUser = string.valueof(SFU[0].get('id')); for(Account a : accountToUpdate){ a.ownerid = SFUser; update a; } } }
This seems to work fine the issue I am having is I am only able to cover 75% of the class due to the "inactive" owner...
Here is my test class:
@isTest public class test_inactiveAccountOwnerChange { static id usr; Private Static Void Init(){ Profile p = [SELECT Id FROM Profile WHERE Name='ACM (Business Movers)']; User u = new User( Alias = 'standt34', Email='standarduser12234@testorg.com', EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', LocaleSidKey='en_US', ProfileId = p.Id, TimeZoneSidKey='America/Los_Angeles', UserName='standarduser123451@testorg.com'); insert u; usr = u.id; account a = new account(); a.Name = 'Test'; a.REG_ADD_LINE_1__c = 'Line 1'; a.REG_ADD_LINE_2__c = 'Line 2'; a.REG_ADD_LINE_3__c = 'Line 3'; a.REG_ADD_LINE_4__c = 'Line 4'; a.REG_ADD_TOWN__c = 'Town'; a.REG_ADD_POSTCODE__c = 'B63 02H'; a.Company_Type__c = 'Limited'; a.OwnerId = u.id; Insert a; } static testMethod void inactiveOwners() { Test.startTest(); init(); String CRON_EXP = '0 0 0 1 1 ? 2025'; String jobId = System.schedule('testScheduledApex', CRON_EXP, new inactiveAccountOwnerChange() ); CronTrigger ct = [select id, CronExpression, TimesTriggered, NextFireTime from CronTrigger where id = :jobId]; System.assertEquals(CRON_EXP, ct.CronExpression); System.assertEquals(0, ct.TimesTriggered); System.assertEquals('2025-01-01 00:00:00', String.valueOf(ct.NextFireTime)); Test.stopTest(); } }I insert a test user as active, insert the account with the active user.. I am unable to set this user to inactive at this point which in turn does not cover the final part of my class lines 12 and 14..
Any ideas on how I can get round this ?
Thanks
According to your code Account owner should be inactive.
System.DmlException: Update failed. First exception on row 0 with id 00519000000thn7AAA; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): User, original object: Account: []
Please let us know if this will help u
I get the same error :(.
Thanks,