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
EricCowherd.ax640EricCowherd.ax640 

Visualforce error since namespace added

I have a Visualforce page that was working when it was a part of an unmanaged package, but when I created a managed package and its required namespace (CI) the page quit working and now displays the following error whenever I click on the button to call it:

 

Invalid field RA_Matched_Account__c for SObject CI__INOW_Reported_Account__c

 

The custom button is using a Content Source of a Visualforce Page.  The RA_Matched_Account__c field is being used to determine whether or not to display a warning message if the field has a value.

 

<!-- Display a warning message if the Reported Account has already been matched -->

<h1>

<apex:pageMessage summary="This Reported Account has already been matched, if you continue 

            your new Account will overwrite the existing one!" severity="warning" strength="3" 

            rendered="{!RepAcct.RA_Matched_Account__c!=''}" />

        </h1> 

 

Obviously the field does not have the CI namespace before it's name, but that is not for a lack of trying (every time I save the CI__ is stripped out).  The getRepAcct method is using fields with the CI namespace, althought it doesn't matter if I have them there or not, the result is the same.

 

public CI__INOW_Reported_Account__c getRepAcct() {

repAcctInfo = [select Id, Name, CI__RA_Street1__c, CI__RA_City__c, CI__RA_StateProv__c, 

CI__RA_Postcode__c, CI__RA_Country__c, RA_Matched_Account__c

from CI__INOW_Reported_Account__c 

where id = :cid];

 

return repAcctInfo;

} 

 

 I have tried everything I can to resolve this issue, but no matter what I do I continue to receive this same error message since creating the namespace.

 

Thanks in advance for any help! 

Best Answer chosen by Admin (Salesforce Developers) 
ciccic

The code that installs Visualforce pages in managed packages has a few bugs ....  It occasionally doesn't rewrite the references to custom objects etc to add the namespace prefix.   Sometimes you can get around this by adding the prefix in the page on your development org, and it gets carried across.  But that technique often fails, as the development org takes the prefix out again when you save the page.  This is what you've found.  The code compiler recognises it as a reference to an object in a managed package but the Appexchange code installer doesn't.

 

When you get to that point, all you can do is to rewite the visualforce page to use another construct that does the same job.   You could try putting the message in an apex:outputPanel with the rendered= bitcontaining the message without the rendered=.  Keep trying until the page gets through without hitting this bug.

 

Rendered= attributes often hit this bug.  So do commandbuttons containing urls.  Complex formulas with a ref to an object or page is likely to hit it too.

 

If you get really stuck and can't find any code-around then make the controller global so you can make a visualforce page locally in the installed org and you can then manually craft the page code.

 

BTW this has been reported several times but is one of those sticky bugs......

All Answers

ciccic

The code that installs Visualforce pages in managed packages has a few bugs ....  It occasionally doesn't rewrite the references to custom objects etc to add the namespace prefix.   Sometimes you can get around this by adding the prefix in the page on your development org, and it gets carried across.  But that technique often fails, as the development org takes the prefix out again when you save the page.  This is what you've found.  The code compiler recognises it as a reference to an object in a managed package but the Appexchange code installer doesn't.

 

When you get to that point, all you can do is to rewite the visualforce page to use another construct that does the same job.   You could try putting the message in an apex:outputPanel with the rendered= bitcontaining the message without the rendered=.  Keep trying until the page gets through without hitting this bug.

 

Rendered= attributes often hit this bug.  So do commandbuttons containing urls.  Complex formulas with a ref to an object or page is likely to hit it too.

 

If you get really stuck and can't find any code-around then make the controller global so you can make a visualforce page locally in the installed org and you can then manually craft the page code.

 

BTW this has been reported several times but is one of those sticky bugs......

This was selected as the best answer
EricCowherd.ax640EricCowherd.ax640

clc,

 

Thank you, I modified the Visualforce markup following your advice and it worked.  Here is the new code for anyone who might be interested:

 

<!--  Second attempt to display the warning message to get around the Apex compiler namespace bug from above 

based upon a reply in the Visualforce developer boards from clc. -->

<apex:outputPanel id="MatchedAccountError" style="font-style:italic; color:red; 

font-size:11pt" rendered="{!RepAcct.RA_Matched_Account__c!=''}">

This Reported Account has already been matched, if you continue your new Account will 

overwrite the existing one!

</apex:outputPanel> 

 

I was still able to use the rendered= although I first made sure it worked without this and then added it in hoping that it wouldn't screw things up.