Wednesday 1 July 2015

ApexPages.currentPage().getParameters().get('id')

Basically all developer using  the above code , I had a confusion when I have used this first time . At that time apex pdf does not have clear definition of methods and classes .
This is the concept of method chaining .

I have divided into 3 steps to know detail concept behind it .

Step1:-
ApexPages is a class in which CurrentPage is a method which returns a PageReference .

Click on the link ApexPages_methods to know about the method and other methods as well .

Step2:-
As step one returns a PageReference  now we can use PageReference method in step2
ApexPages.currentPage().getParemeters()
getParemeters() is a method in PageReference class which retuns a Map .

Click on the link PageReference_methods to know about the method and other methods as well .

Step 3 :-
ApexPages.currentPage().getParemeters().get()/put()

As step2 returns Map so we can use map methods in step3 .
Click on the link Map_methods to know about the method and other methods as well .

What else we can do with it : -

1.You can get the full url by using belwo code :

ApexPages.currentPage().getUrl();

2.You can get the IP address from belwo code .

ApexPages.currentPage().getHeaders().get('X-Salesforce-SIP');