• dkss
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

I have just created an Apex Class that implements the InstallHandler interface, and have associated it with a managed package. However, when I install my package, the SObject.put(SObjectField f, Object value) are throwing a "Field is not editable" SObjectException. I found this strange, since the error is being thrown before I even do DML --- i.e. the actual put() call is throwing the error. I thought this must be a Field-Level Security issue, so I made sure that the System Admin profile (both in my package development org, and in the org into which I am installing my package) has read/write access to the field in question. But I still get the error.

 

Digging deeper, I did some debug output  in my install script on the Schema information for the field in question and sent it to myself in an email. To my surprise, the field was not even accessible, much less editable! I then checked accessibility of the object. Again, isAccessible() returned FALSE! So I checked some other objects --- same thing. Contact, Account, Contact.LastName, Account.Name --- isAccessible() for all of these fields/objects returns FALSE. 

 

Am I missing something? Is this just a bug in the Schema information? Or do InstallHandlers really not have access to any objects/fields? This can't be possible.

 

here is the code:

 

global abstract class InstallScript implements InstallHandler {

	// The module that we will be installing
	protected String moduleName;

	// Set the name of the module associated with this package install 
	global abstract void setModule();
	
	// Any additional on install logic should be defined in this method
	global abstract void onInstallLogic(InstallContext ctx);

	global void onInstall(InstallContext ctx) {
		// Set the module that we are running in
		setModule();
		
		if (moduleName != null) {
			
			// See if a StaticResource containing new pages for this module yet exists
			StaticResource sr;
			try {
				sr = [select Id, Body, Name, NamespacePrefix from StaticResource where Name = :(moduleName + 'Pages')];
			} catch (Exception ex) {
				// No pages exist for this module
			}
			if (sr != null) {
				String username,profileId,accessible,createable,updateable,localname,name,body,debugString;
				DescribeFieldResult dfr;
				SObjectField f;
				try {
					username = UserInfo.getUserName();
					profileId = UserInfo.getProfileId();
					f = Page__c.Layout__c;
					dfr = f.getDescribe();
					accessible = dfr.isAccessible() + '';
					createable = dfr.isCreateable() + '';
					updateable = dfr.isUpdateable() + '';
					localname = dfr.getLocalName();
					name = dfr.getName();
					body = sr.Body.toString();
					
					debugString = 
						'Username: ' + ((username != null) ? username : 'null') 
						+ 'ProfileId: ' + ((profileId != null) ? profileId : 'null')
						+ ', Contact.Accessible: ' + Contact.SObjectType.getDescribe().isAccessible()
						+ ', Contact.LastName.Accessible: ' + Contact.LastName.getDescribe().isAccessible()
						+ ', Page__c.Accessible: ' + Page__c.SObjectType.getDescribe().isAccessible()
						+ ', Page__c.Name.Accessible: ' + Page__c.Name.getDescribe().isAccessible()
						+ ', Layout__c.Accessible: ' + accessible
						+ ', Layout__c.Createable: ' + createable
						+ ', Layout__c.Updateable: ' + updateable
						+ ', Layout__c.getLocalName: ' + localname
						+ ', Layout__c.getName: ' + name
						+ ', body: ' + body;
                               } catch (Exception ex) {

                                    // Send email
                               }
                         }
                   }
             }
}

The actual InstallScript is a simple implementation of the abstract class. The important thing to note is that all of the isAccessible() calls are returning FALSE.

 

I received the same results in both API versions 24 and 25.

 

Any ideas?

 

Zach McElrath

Skoodat LLC