• Pavlo Shchur 31
  • 0 Points
  • Member since 2018

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 4

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.
I am conducting an Apex test for ChatterAnswersAuthProviderRegTest, as I run this test, I encounter the following error message.

System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [ProfileId]: [ProfileId]

I am curious to know where to go about obtaining the the id of a Chatter Answers Profile. I have attempted to call ProfileId though it appears the profile Id's I have available do not seem to allow. Or any steps I need to take.
private class ChatterAnswersAuthProviderRegTest {
    static testMethod void validateCreateUpdateUser() {
        User thisUser = [ select Id from User where Id = :UserInfo.getUserId() ];
        System.runAs ( thisUser ) {
            Auth.UserData userData = new Auth.UserData('testId', 'testFirst', 'testLast',
            'testFirst testLast', 'no-reply@salesforce.com', null, 'testuserlong', 'en_US', 'facebook',
            null, new Map<String, String>{'language' => 'en_US'});
            ChatterAnswersAuthProviderRegistration reg = new ChatterAnswersAuthProviderRegistration();
            Profile[] p = [SELECT Id FROM Profile WHERE Name = 'System Administrator'];
            User[] adminUser = [SELECT Id, Firstname, Lastname FROM User WHERE IsActive = true and ProfileId =: p[0].Id LIMIT 1];
            User newUser = reg.createUser(null, userData);
            System.assert(newUser != null, 'A new user should have been created');
            System.assertEquals(newUser.Firstname, 'testFirst', 'First name should have been same');
            System.assertEquals(newUser.Lastname, 'testLast', 'Last name should have been same');
            System.assertEquals(newUser.Email, 'no-reply@salesforce.com', 'Email should have been same');
            Contact c = new Contact();
            c.AccountId = (newUser.Username.split('@'))[0];
            c.LastName = 'contactLast';
            newUser.Alias = 'firstusr';
            newUser.TimeZoneSidKey = 'America/Los_Angeles';
            newUser.LocaleSidKey = 'en_US';
            newUser.EmailEncodingKey = 'UTF-8';
            newUser.LanguageLocaleKey = 'en_US';
            newUser.ContactId = c.Id;
            Auth.UserData updateUserData = new Auth.UserData('testId', 'updatedFirst', 'updatedLast',
            'updatedFirst updatedLast', 'no-reply@new.salesforce.com', null, 'testuserlong', 'en_US', 'facebook',
            null, new Map<String, String>{'language' => 'en_US'});
            reg.updateUser(newUser.Id, null, updateUserData);
            User dbUser =  [SELECT Id, Firstname, Lastname, Email FROM User WHERE Id = :newUser.Id];
            System.assertEquals(dbUser.Firstname, 'updatedFirst', 'First name should have been updated');
            System.assertEquals(dbUser.Lastname, 'updatedLast', 'Last name should have been updated');
            System.assertEquals(dbUser.Email, 'no-reply@new.salesforce.com', 'Email should have been updated');

something strange happend, i have created a custom object,its related tab and linked it with the a user's profile, the profile has access on that object and app ,even i set the tab to "Default On" ,i have checked thoroughly but still i am not able to see the tab and not even in the "customize tabs" page,when logged in with that user account. i wonder what migh have happend ?

Hi All,


I have a code which are getting all the fields name and their properties like api name, label , data type.


Now for deployed the code I am getting this exception :

System.SObjectException: Field Lead.LastViewedDate is inaccessible in this context.


It seems that there is a field "LastViewedDate" , I have checked all fields but I am not able to find this.

Please let me know if any one have any idea.