function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
test test 5030test test 5030 

Getting error in post install script in managed packe

Hello,

We are created a apex code to update view with visualforce page in managed package. We are calling apex code as a post install script in the managed package and below is the code.

global class PostInstallClass implements InstallHandler {
global void onInstall(InstallContext context) {
MetadataService.MetadataPort service = new MetadataService.MetadataPort();
service.SessionHeader = new MetadataService.SessionHeader_element();
service.SessionHeader.sessionId = UserInfo.getSessionId(); 
MetadataService.ActionOverride actionOverrides1 = new MetadataService.ActionOverride();
actionOverrides1.actionName = 'View';
actionOverrides1.type_x  = 'Visualforce';
actionOverrides1.content = 'VFAPIPage';
actionOverrides1.comment = 'Configure Visual Force page with Opportunity.';
MetadataService.CustomObject customObject = new MetadataService.CustomObject();
customObject.fullName = 'Opportunity'; 
customObject.actionOverrides = new MetadataService.ActionOverride[] { actionOverrides1 };
service.updateMetadata( new MetadataService.Metadata[] { customObject });
}
}

The packaging is not installaling and giving post install error message and below is the error message.

Message : You have uncommitted work pending. Please commit or rollback before calling outLine no : 10822 getStackTraceString Class.recoapi.MetadataService.MetadataPort.updateMetadata: line 10822, column 1 Class.recoapi.PostInstallClass.UpdateView: line 21, column 1 Class.recoapi.PostInstallClass.onInstall: line 3, column 1null

The apex code is working fine in my organization but its not woking in destion instance while installing managed package with post install script.

Please share possible options with us, to change opportunity view with visualforce page using apex code.