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
cirruscg1cirruscg1 

Getting "Initial term of field expression must be a concrete SObject" error

I'm getting a strange error when trying to save/compile some code.

 

I have the following static method defined:

public class Util {
public static Boolean isSamePage(PageReference p1, PageReference p2) { String p1_url = p1.getUrl(); String p2_url = p2.getUrl(); System.debug(System.LoggingLevel.INFO, '\n**** p1 [1]: '+p1_url+'\n**** p2 [1]: '+p2_url); // trim args off if (p1_url.indexOf('?') != -1) p1_url = p1_url.substring(0, p1_url.indexOf('?')); if (p2_url.indexOf('?') != -1) p2_url = p2_url.substring(0, p2_url.indexOf('?')); System.debug(System.LoggingLevel.INFO, '\n**** p1 [2]: '+p1_url+'\n**** p2 [2]: '+p2_url); if (p1_url == p2_url) return true; return false; }
}

 

And I'm getting the "Initial term of field expression must be a concrete SObject: String" compile-time error on the following line in my VF page controller extension:

 

public TemplateExt(ApexPages.StandardController c) {
	this.page = (Util.isSamePage(ApexPages.currentPage(), Page.SelectTemplate) ? 'select' : 'edit'); // <<<< ERROR HERE

	// ...
}

 

Also, if I comment out the above line, I'm getting the same error on lines like:

PageReference p = Page.SelectTemplate;

 

help?

Best Answer chosen by Admin (Salesforce Developers) 
Shashikant SharmaShashikant Sharma

You must have a Boolean property or variable Page in your controller , Apex has reserved Page as KeyWord  so you need to change anme of this variable to something else

 

and use like


this.pageMode = (Util.isSamePage(ApexPages.currentPage(), Page.SelectTemplate) ? 'select' : 'edit'); 

All Answers

Shashikant SharmaShashikant Sharma

You must have a Boolean property or variable Page in your controller , Apex has reserved Page as KeyWord  so you need to change anme of this variable to something else

 

and use like


this.pageMode = (Util.isSamePage(ApexPages.currentPage(), Page.SelectTemplate) ? 'select' : 'edit'); 

This was selected as the best answer
Shashikant SharmaShashikant Sharma

You must be having String property or variable with Name as "Page" rather the Boolean that i mentioned in last post  just chaneg its Name to any thing else it will work Page is a keyword in Apex so you can not have any variable or property name as page.

Ankit AroraAnkit Arora

Yes indeed you can use page as variable but cirruscg1 are you sure you have mentioned the line where you are facing the error. Am asking this because I can save this on my organization. It will be good if you provide the full code if the problem still persists.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

bob_buzzardbob_buzzard

This error means that there's a dotted notation expression that doesn't evaluate correctly, so the compiler assumes you meant to access an sobject field and throws an error.

 

What's odd is that it looks like you are getting this error when using 'Page.SelectTemplate' - normally if there's an issue with the page name, you receive an error that the page doesn't exist.

 

Looking at the controller in more detail, it appears you have a property called 'page':

 

this.page = (Util.isSamePage(...

 

I suspect this is conflicting with the system's Page class, so the expression 'Page.SelectTemplate' indicates to the compiler that your page property (which is a String I'd guess) has a property called SelectTemplate, which of course it doesn't.

 

You have a couple of options here:

 

(1) Change the name of your property from page to something else (e.g. thePage)

(2) Prefix all references to the system page class with System e.g. System.Page.SelectTemplate

 

I'd go with the first if I were you!

 

cirruscg1cirruscg1

You were all right. Thanks for your help!