You need to sign in to do that
Don't have an account?
PostInstall script doesn't work
Hello everyone! I am new to Apex coding.
I am trying to create an Apex class to create some default records for my custom Object. Here is my PostInstall class:
global without sharing class PostInstall implements InstallHandler {
global void onInstall(InstallContext context) {
Account a = new Account(Name = 'Hello');
insert a;
}
}
I create a unit test for it:
public class UnitTestClass {
@isTest
static void testInstallScript() {
PostInstall postinstall = new PostInstall();
Test.testInstall(postinstall, null);
Test.testInstall(postinstall, new Version(0,1,0), true);
Account[] a = [select id from Account where Name = 'Hello'];
System.assertEquals(a.size(), 1, 'Hehe');
}
}
And the UnitTestClass is correct. But when I try to create a package and install it to another org, the PostInstall class isn't even called to create records for Account object. Can you help me with this problem? Thank you so much.
Is the PostInstall class added to the package.xml file? Thanks