How to Identify the IP Address of the Server From Which Our Environment Operates in Salesforce
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.
- First, enable access to the external service we will use to identify our IP address:
- Access the Setup screen by clicking the gear icon at the top of the screen and selecting the Setup option from the menu.
- In the Setup screen, click on the Quick Find search field, type the words "Remote Site," and select the "Remote Site Settings" option.
- In the All Remote Sites page, click the New Remote Site button.
- 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.
- In the Remote Site URL field, enter the value "http://icanhazip.com." Your screen should look like the one in the following image:
- Click Save.
- Access the Setup screen by clicking the gear icon at the top of the screen and selecting the Setup option from the menu.
- Open the Developer Console by clicking the gear icon at the top of the screen and selecting the "Developer Console" option.
- In the Developer Console, click the Debug menu.
- Select "Open Execute Anonymous Window" or use the shortcut Ctrl + E.
- 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());
- Check the "Open Log" box.
- Click Execute.
- 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.