6

I want to create a trigger when user (or customer) make changes to record, then I want record their current IP. Does anybody know how that works?

Thanks

7

I have used the below code to get the IP address of the logged/current user. Hope this helps. Thanks

    Map<String, String> headersMap = ApexPages.currentPage().getHeaders();  

    // True-Client-IP has the value when the request is coming via the caching integration.
    String ipAddress = headersMap.get('True-Client-IP');

    if (String.isEmpty(ipAddress)) {
        // X-Salesforce-SIP has the value when no caching integration or via secure URL.
        // get IP address when no caching (sandbox, dev, secure urls)
        ipAddress = headersMap.get('X-Salesforce-SIP');
    } 

    if (String.isEmpty(ipAddress)) {
        // get IP address from standard header if proxy in use
        ipAddress = headersMap.get('X-Forwarded-For');
    } 

    return ipAddress;
  • Please check this as answer if it resolve the issue. It'll be helpful for others also in future. Good Luck and Thanks – amidstCloud Jun 17 '15 at 17:54
  • Hey, the problem is we want to get the source IP field from login history object. We do not know how to get it. We can get the IP but the system randomly chooses a one. Do you have any idea about it? – Dananjaya Pathirana Jun 18 '15 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.