Retrieve Visualforce pages

Find how to retrieve Visualforce pages from Salesforce org using manifest file & SFDX

Summery:

  1. Retrieve Single VF Page
  2. Retrieve Multiple Visualforce Pages
  3. Retrieve All Visualforce pages
  4. Fetch Visualforce pages with SFDX

Pro Tip: Visualforce pages are refer as ApexPages.

Retrieve LWC with menifest file

Retrieve Single Visualforce page

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <name>ApexPage</name>
        <members>CommunitiesLogin</members>
    </types>
    <version>62.0</version>
</Package>

Fetch Multiple Visualforce pages

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <name>ApexPage</name>
        <members>CommunitiesLanding</members>
        <members>CommunitiesLogin</members>
    </types>
    <version>62.0</version>
</Package>

Retrieve All * Visualforce pages

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <name>ApexPage</name>
        <members>*</members>
    </types>
    <version>62.0</version>
</Package>

Retrieve Visualforce pages with SFDX

sfdx force:source:retrieve -m ApexPage:VisualforcePageName

What is ApexPage in Salesforce?

Visualforce pages are stored as the ApexPage metadata type. Retrieving them gives you the .page markup file and a small meta XML file for each page.

Steps to retrieve it in VS Code

  1. Open your Salesforce DX project in VS Code and authorize your org with SFDX: Authorize an Org.
  2. Open manifest/package.xml, or create the file, and paste the XML shown above.
  3. Right-click package.xml and choose SFDX: Retrieve Source in Manifest from Org.
  4. When the command finishes, open the folder force-app/main/default/pages to see the retrieved files.

Use the API name of the page. Use * to retrieve every Visualforce page in the org.

Retrieve it with the Salesforce CLI

If you prefer the terminal, run one of these commands from your project folder:

sf project retrieve start --manifest manifest/package.xml
sf project retrieve start --metadata ApexPage:CommunitiesLogin

Where the files are saved

After a successful retrieve, the files are placed inside your project, for example in force-app/main/default/pages/CommunitiesLogin.page.

Common problems and fixes

  • Entity of type ApexPage cannot be found: check the spelling and the API name of the member, and make sure you are authorized to the correct org.
  • Nothing was retrieved: run sf org list to confirm the default org, and check that the component actually exists there.
  • API version: the examples use version 62.0. You can use a higher version if your org supports it.

FAQ

Why is the type called ApexPage and not VisualforcePage?
ApexPage is the name the Metadata API uses for Visualforce pages.

Do I also need the controller?
Yes, if the page uses a custom controller. Controllers are Apex classes, so add the ApexClass type to the package.xml.

Leave a Reply