You need to sign in to do that
Don't have an account?
davix
Variable does not exist: ApexPages
I must be missing something but I'm new enough to not know what it is. Thanks for any help.
Error : Variable does not exist: ApexPages
Error : Variable does not exist: ApexPages
public class myClass { public String getIP() { String ip = null ; /* Don't work * String ip = ApexPages.currentPage().getHeaders().get('True-Client-IP'); if (ip == '') { ip = ApexPages.currentPage().getHeaders().get('X-Salesforce-SIP'); }*/ system.debug(ApexPages); Map<String, String> entetes = ApexPages.currentPage().getHeaders(); if(entetes != null) { ip = entetes.get('True-Client-IP'); system.debug('-------Client IP------'+ip); if(ip == null) ip = entetes.get('X-Salesforce-SIP'); system.debug('-------Salesforce IP------'+ip); } return ip ; } }
Because when you are going to call ApexPages.currentPage()........ here the link breaks becuase there is not any active page so of which page's headers it should returns, hence you got the NullPointerException.
I hope you got the Problem and understanded the concept behind it.
So you have to find some other way to get the IP address of the current logged In user. May be you should use any workaround at the CTI side or something else.
Well, I'll try to find something for you. Stay tuned.
Thanks
All Answers
ApexPages is not a variable to print it is a class so you cannot use
system.debug(ApexPages);
instead use Please refer below links for more information on ApexPage.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_apexpages.htm
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_System_ApexPages_currentPage.htm
Hope this helps you!
Please accept my solution as Best Answer if my reply was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, you can give me kudos.
Thanks and Regards
Sandhya
Error is saying something meaningful. Because ApexPages is a class and we can not debug or pring something when we are directly trying to print the class name.
So if you comment out line no. 10 then your code will compile successfully.
Note - We can debug or print the object of any class but not direct class name.
Hope this helps. Please revert back to me if you have any further queries & Please mark this answer as the right answer so that others can get benifit from this.
Thanks,
Kapil Kaushik
"System.NullPointerException: Attempt to de-reference a null object"
It is for this reason that I had added this line.
On which line you are getting this error
Thanks
Sandhya
You should just be able to put a value on the headers map:
please refer below link.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_System_PageReference_getHeaders.htm
Thanks and Regards
Sandhya
I tried with only this code, it don't work
Your line - ApexPages.currentPage().getHeaders().get('True-Client-IP') ; is not working in your case so you can replace the above line with the below one :
ApexPages.currentPage().getHeaders().get('X-Salesforce-SIP') ;
Is it worthy for you ? Please write
Thanks,
Kapil Kaushik
One query - How you are trying this code ? Is it controller of any page ? OR
You are trying to run it from Anonymous window of Developer console ?
The reason is because there is not any page via which we can headers. So be sure that you are using this code as a controller of any VF page. If not, then please try to use that code as the controller and try to print "ip_client" property on the VF page.
And let me know for any further queries.
Finally I would request, if possible can you please post your more code snippet and the way how you are using it. We will get more clear and can suggest you some good workarounds.
Thanks for your quick reply.
If possible, Please post some more code and be sure that the things which comes after "ApexPages.something.something.something" is only going to work if that code is invoked from a VF page or somehow from test classes.
Please clear our queries.
CTI adaptater content :
Because when you are going to call ApexPages.currentPage()........ here the link breaks becuase there is not any active page so of which page's headers it should returns, hence you got the NullPointerException.
I hope you got the Problem and understanded the concept behind it.
So you have to find some other way to get the IP address of the current logged In user. May be you should use any workaround at the CTI side or something else.
Well, I'll try to find something for you. Stay tuned.
Thanks
Thanks