SHARE
TWEET

Untitled

a guest Jul 17th, 2017 42 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. User testUser = new User(stuff goes here);
  2. testUser.UserPermissionsKnowledgeUser = true;
  3. System.runAs (testUser) {
  4.     //this works fine
  5.     system.debug( [select id, KnowledgeArticleId from internal__kav where PublishStatus= 'Draft'  AND Language = 'en_US'  limit 1]);
  6. }
  7.    
  8. global class testbatchimplements Database.Batchable<sObject>{
  9.     global Database.QueryLocator start(Database.BatchableContext BC){      
  10.         return Database.getQueryLocator([select id, KnowledgeArticleId from internal__kav where PublishStatus= 'Draft'  AND Language = 'en_US']);
  11.     }
  12.  
  13.     global void execute(Database.BatchableContext BC, List<sObject> scope){}
  14.  
  15.     global void finish(Database.BatchableContext BC){}
  16. }
  17.  
  18. User testUser = new User(stuff goes here);
  19. testUser.UserPermissionsKnowledgeUser = true;
  20. System.runAs (testUser) {
  21.     //this works fine
  22.     Test.startTest();
  23.     database.executeBatch(new testbatch());
  24.     Test.stopTest();
  25. }
  26.    
  27. global class testScheduled implements Schedulable {
  28.     global void execute(SchedulableContext SC){
  29.         Database.executeBatch(new testBatch());
  30.     }
  31. }
  32. User testUser = new User(stuff goes here);
  33. testUser.UserPermissionsKnowledgeUser = true;
  34. System.runAs (testUser) {
  35.     // fails
  36.     Test.startTest();
  37.     String cron = '0 0 * * * ?';
  38.     System.schedule('test',cron, new testScheduled());
  39.     Test.stopTest();
  40. }
RAW Paste Data
Top