Skip to content

Instantly share code, notes, and snippets.

@greenstork
Last active December 27, 2015 02:29
Show Gist options
  • Save greenstork/7253022 to your computer and use it in GitHub Desktop.
Save greenstork/7253022 to your computer and use it in GitHub Desktop.
public with sharing class FutureTest {
@future
public static void createAccountFuture() {
Account a = new Account(Name='Test Account');
//User with the standard Read Only profile should not be able to insert an account
insert a;
}
///////////////TESTS////////////////////
static testMethod void testFutureCall() {
Profile p = [SELECT id FROM Profile WHERE Name ='Read Only' LIMIT 1];
user u = new User(alias = 'person', email='guest@testpkg.com',
emailencodingkey='UTF-8', firstname='Test', lastname='Person', languagelocalekey='en_US',
localesidkey='en_US', profileid = p.id,
timezonesidkey='America/Los_Angeles', username='guest@testpkg.com');
insert u;
Test.startTest();
system.runAs(u) {
FutureTest.createAccountFuture();
}
Test.stopTest();
Account[] createdAcounts = [SELECT id FROM Account WHERE Name = 'Test Account'];
system.assert(createdAcounts.size() == 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment