Activity Forums Salesforce® Discussions How to get Ip Address of User in Salesforce Apex?

  • Suraj

    Member
    April 13, 2017 at 4:59 am

    Hi Saurabh,

    You can use this,

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

    'True-Client-IP' - when the request is coming via the caching integration.

    'X-Salesforce-SIP' - when the request is not via caching integration (sandbox, developer edition orgs) or via the secure url.

  • Radhakrishna

    Member
    April 13, 2017 at 5:00 am

    Hello Saurabh,

    This may help you.
    Below is some code to get you started. You will need to add it to your controller or controller extension

    public static String GetUserIPAddress() {

    string ReturnValue = '';

    ReturnValue = ApexPages.currentPage().getHeaders().get('True-Client-IP');

    if (ReturnValue == '') {

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

    } // get IP address when no caching (sandbox, dev, secure urls)

    system.debug('USER IP ADDRESS: ' + ReturnValue);

    return ReturnValue;

    } // GetUserIPAddress

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos