+ Start a Discussion
udayar_jayamudayar_jayam 

Get Current Page URL in Apex Class

Hi All,

      How to write apex class for to get dynamic url in any record and objects.

Puja_mfsiPuja_mfsi

Hi,

To get the URL of the current page u can use ApexPages.currentPage() methods.

 

String hostVal  = ApexPages.currentPage().getHeaders().get('Host');
String urlVal = Apexpages.currentPage().getUrl();
String URLL = 'https://' + hostVal+ urlVal;                       // Add the hostVal and urlVal and it will give u the URL value

Please refer the following link:

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_pages_pagereference.htm

 

 

 

Please let me know if u have any problem on same,and if this post help you please give KUDOS by click on star at left.

 

Devender MDevender M
Hi

In order to get the url in apex class u can use Apexpages.currentPage().getUrl();
udayar_jayamudayar_jayam

thanks for reply Puja and dev how to get the URL of My oppaortunity List view

Puja_mfsiPuja_mfsi

Hi,

you need to findout the keyPrefix of opportunity object 

 

public string findObjectAPIName( String ObjectName ){
               String keyPrefix = '';

               schema.DescribeSObjectResult d = Schema.getGlobalDescribe().get(ObjectName).getDescribe();

                keyPrefix  = d.getKeyPrefix();

               return keyPrefix ;
  }

 

and use like that :

String hostVal  = ApexPages.currentPage().getHeaders().get('Host');

String prefix = findObjectAPIName('Opportunity');

 

String URLL = 'https://' + hostVal+ '/'+prefix ;   

 

 

Please let me know if u have any problem on same,and if this post help you please give KUDOS by click on star at left.

vbsvbs

@Udayar - If using in VF page try this:

<apex:outputLink value="{!URLFOR($Action.Opportunity.List,$ObjectType.Opportunity)}">
   Click for Opportunity List here
</apex:outputLink>

 

Sailaja KunchalaSailaja Kunchala
You can also use String.escapeSingleQuotes(ApexPages.currentPage().getParameters().get('url_param'));