How to Identify the IP Address of the Server From Which Our Environment Operates in Salesforce

ליאור נכתב על ידי ליאור לביא, עודכן בתאריך 29/10/2023

Sometimes, we might want to allow access from one Salesforce environment installed on a specific server to another environment installed on a different server. For example, from our production environment to a development environment. To do this, we need to make a request from our production environment to the development environment with the user authentication details from the development environment. The problem arises when a user from the development environment has a profile restricted to specific IP ranges. How do we know if our production server falls within these ranges? In the following example, you can find a simple solution to run from the Developer Console.

  1. First, enable access to the external service we will use to identify our IP address:
    1. Access the Setup screen by clicking the gear icon at the top of the screen and selecting the Setup option from the menu. Select Setup
    2. In the Setup screen, click on the Quick Find search field, type the words "Remote Site," and select the "Remote Site Settings" option.
    3. In the All Remote Sites page, click the New Remote Site button.
    4. In the Remote Site Name field, enter the value "GetMyIP." In principle, it's okay to choose another name as long as it doesn't contain spaces, is unique, starts with a letter, contains only letters, numbers, and underscores, doesn't end with an underscore, and doesn't contain consecutive underscores.
    5. In the Remote Site URL field, enter the value "http://icanhazip.com." Your screen should look like the one in the following image: Remote Site Edit
    6. Click Save.
  2. Open the Developer Console by clicking the gear icon at the top of the screen and selecting the "Developer Console" option.
  3. In the Developer Console, click the Debug menu.
  4. Select "Open Execute Anonymous Window" or use the shortcut Ctrl + E.
  5. Paste the following code into the Enter Apex Code window:
    HttpRequest req = new HttpRequest();
    req.setEndpoint('http://icanhazip.com/');
    req.setMethod('GET');
    Http httpReq = new Http();
    HttpResponse res = httpReq.send(req);
    System.debug(res.getBody());
    
  6. Check the "Open Log" box.
  7. Click Execute.
  8. In the tab that opens, check the "Debug Only" checkbox.

The IP address of the server your environment is running on should appear in the remaining log entry.