You need to sign in to do that
Don't have an account?
Dritter
System.UnexpectedException: No more than one executeBatch can be called from within a testmethod
My test class keeps getting this error when I push to production. I found the following article (https://help.salesforce.com/apex/HTViewSolution?id=000176562&language=en_US) and added the code to lines at the bottom. However, I keep getting a Compile Error: unexpected token: ')' at line 49 column 51.
Is this the best way to resolve the original error? If so, any ideas on why I'm getting the Compile Error and how to overcome it? I've tried a few things but they all result in the same error.
/************************************************************************************ ** Module Name : UserCleanUp ** ** Description : This class deactivates portal users setup by the website and ** irostering. It also deactivates Salesforce users that haven't logged in in the ** last 90 days with the exception of Guest Site Users. ** ** Technial Info : <Batch Apex Class> ** ** Author : ** Revision History:- ** Version Date Author ** 1.0 1/6/15 ************************************************************************************/ global class KapUserCleanUp implements Database.Batchable<sObject>{ datetime myDateTime = datetime.now(); datetime newDateTime = myDateTime.addHours(-3); datetime inactiveDateTime = myDateTime.addDays(-90); //System.debug('current time: ' + myDateTime); //System.debug('newDateTime time: ' + newDateTime); //System.debug('inactiveDateTime time: ' + inactiveDateTime); global Database.querylocator start(Database.BatchableContext BC){ return Database.getQueryLocator([SELECT Email,Id,LastLoginDate FROM User WHERE (IsPortalEnabled = True AND IsActive = true AND (lastLoginDate < :newDateTime OR lastLoginDate = null)) OR (IsPortalEnabled = false AND isActive = true AND lastLoginDate < :inactiveDateTime AND LastName != 'Site Guest User')]);} global void execute(Database.BatchableContext BC, List<User> users){ System.debug('Users retrieved ' + Users); for (User u : users) { u.isActive = false; System.debug(u.id + ' ' + u.email + ' will be deactivated' + u.lastLoginDate); } Database.SaveResult[] srList = Database.update(users, false); for (Database.SaveResult sr : srList){ if (!sr.isSuccess()) { //Operation failed, so get all errors for(Database.Error err : sr.getErrors()){ System.debug('The following error has occurred.'); System.debug(err.getStatusCode() + ': ' + err.getMessage()); } } } } global void finish(Database.BatchableContext BC){ if(!Test.isRunningTest) Database.executeBatch(new MySecondBatchJob)); } }
Looking again, the issue isn't that there is a bonus closing bracket, rather missing an opening bracket. The new operator invokes the MySecondBatchJob constructor, which needs to be followed by pair of brackets:
All Answers
You only open a single bracket as part of the executeBatch function invocation, so you only need to close a single one:
I removed the bonus bracket, but when I click save it still produces the syntax error:
Compile Error: unexpected token: ')' at line 49 column 51
I have been getting conflicting advice from other developers. Does the code belong in the main class (picture above) or in my test class?
Thanks for the help!
Looking again, the issue isn't that there is a bonus closing bracket, rather missing an opening bracket. The new operator invokes the MySecondBatchJob constructor, which needs to be followed by pair of brackets: