How to Retrieve Tabs, Apps, and Apex Classes in Salesforce?

Question

I am using sf project retrieve to pull metadata from my Salesforce Dev Hub into my local project. My package.xml retrieves Apex triggers but does not fetch custom applications (Lightning apps), custom tabs, Apex classes, or custom fields. How can I modify package.xml to retrieve them?

Answer

In Salesforce, retrieving metadata using sf project retrieve requires explicitly specifying the metadata components in package.xml. By default, wildcard retrieval (<members>*</members>) works for some components but not for all. Below is a detailed explanation of how to retrieve missing components like custom applications (Lightning apps), custom tabs, Apex classes, and custom fields.

1. Retrieving Custom Applications (Lightning Apps)

Lightning apps are stored under the CustomApplication metadata type. If your app is named “My App LWC”, add the following to package.xml:

<types>
    <members>My_App_LWC</members>
    <name>CustomApplication</name>
</types>

Once added, retrieve it using:

sf project retrieve start -o $user --manifest manifest/package.xml

2. Retrieving Custom Tabs

Custom tabs fall under the CustomTab metadata type. To retrieve all custom tabs, use:

<types>
    <members>*</members>
    <name>CustomTab</name>
</types>

If you want to retrieve a specific tab (e.g., “Employee_Tab”), modify it as follows:

<types>
    <members>Employee_Tab</members>
    <name>CustomTab</name>
</types>

Then run:

sf project retrieve start -o $user --manifest manifest/package.xml

3. Retrieving Apex Classes

By default, Apex classes are not retrieved unless explicitly mentioned in package.xml. For example, to retrieve a class named “HelloWorld”, use:

<types>
    <members>HelloWorld</members>
    <name>ApexClass</name>
</types>

Retrieve it using:

sf project retrieve start -o $user --manifest manifest/package.xml

If you want to retrieve all Apex classes, replace HelloWorld with *:

<types>
    <members>*</members>
    <name>ApexClass</name>
</types>

4. Retrieving Custom Fields

To retrieve a specific custom field, include both the object name and field API name. For example, if you created a custom field Hello_World__c on the Account object:

<types>
    <members>Account.Hello_World__c</members>
    <name>CustomField</name>
</types>

To retrieve all custom fields for an object, use:

<types>
    <members>Account.*</members>
    <name>CustomField</name>
</types>

Run the retrieve command:

sf project retrieve start -o $user --manifest manifest/package.xml

5. Finding Available Metadata Types

If you’re unsure about which metadata types to use, retrieve a list of all available metadata types in your org using:

sf project retrieve metadata-types -o $user

This will help you determine the correct names for metadata components like custom objects, fields, and applications.

Final Steps

  1. Modify package.xml to include all necessary components.
  2. Run:
sf project retrieve start -o $user --manifest manifest/package.xml

3. Verify that all metadata components (tabs, apps, Apex classes, and fields) are retrieved in your project.

Job-Oriented Salesforce Course with Real-Time Projects and Money Back Guarantee

Our Salesforce course is designed to give you a comprehensive understanding of the Salesforce platform, equipping you with the key skills needed to excel in the CRM industry. Covering essential modules such as Salesforce Admin, Developer, and AI, the program combines theoretical learning with hands-on application. Through real-world projects and practical exercises, you’ll gain the expertise to tackle complex business challenges using Salesforce solutions. Our experienced instructors ensure you develop both technical proficiency and industry knowledge to succeed in the Salesforce ecosystem.

In addition to technical training, our Salesforce training in Hyderabad provides personalized mentorship, certification support, and interview coaching to enhance your career opportunities. With access to in-depth study materials, hands-on project experience, and dedicated guidance, you’ll be well-prepared for certification exams and real-world scenarios. Start your Salesforce journey with us and open the door to exciting career possibilities. Sign up for a Free Demo today!

0
Would love your thoughts, please comment.x
()
x