Enroll for free demo AI ML COURSE
How to Fix “Cannot Find Declaration of Element ‘CustomObject'” Error

How to Fix “Cannot Find Declaration of Element ‘CustomObject'” Error

On July 20, 2026, Posted by , In Salesforce Technical Questions, With Comments Off on How to Fix “Cannot Find Declaration of Element ‘CustomObject'” Error
How to Fix "Cannot Find Declaration of Element 'CustomObject'" Error

Question:

Why am I getting the error “cvc-elt.1.a: Cannot find the declaration of element ‘CustomObject'” while adding custom fields to the Case object using the Salesforce Metadata API?

When trying to add custom fields to the Case object via the Salesforce Metadata API, I received the error “cvc-elt.1.a: Cannot find the declaration of element ‘CustomObject'”. I created a project with an SFDX manifest and followed the correct folder structure, but encountered this error. Here’s the XML I used to define multiple custom fields for the Case object:

<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
    <label>Case</label>
    <fields>
        <fullName>Net_Promoter_Score__c</fullName>
        <label>Net Promoter Score</label>
        <type>Number</type>
        <precision>2</precision>
        <scale>0</scale>
    </fields>
    <fields>
        <fullName>Product_Satisfaction__c</fullName>
        <label>Product Satisfaction</label>
        <type>Picklist</type>
        <picklist>
            <picklistValues>
                <fullName>Very Satisfied</fullName>
                <default>false</default>
            </picklistValues>
            <picklistValues>
                <fullName>Satisfied</fullName>
                <default>false</default>
            </picklistValues>
            <picklistValues>
                <fullName>Neutral</fullName>
                <default>false</default>
            </picklistValues>
        </picklist>
    </fields>
    <fields>
        <fullName>Service_Rating__c</fullName>
        <label>Service Rating</label>
        <type>Picklist</type>
        <picklist>
            <picklistValues>
                <fullName>Excellent</fullName>
                <default>false</default>
            </picklistValues>
            <picklistValues>
                <fullName>Good</fullName>
                <default>false</default>
            </picklistValues>
            <picklistValues>
                <fullName>Average</fullName>
                <default>false</default>
            </picklistValues>
        </picklist>
    </fields>
</CustomObject>

Answer:

The error you’re encountering is due to the incorrect XML structure. Specifically, the CustomObject element you’re trying to define is being treated as an object element, which isn’t valid in the context of metadata for custom fields. To resolve this, you need to ensure that you’re using the correct element structure.

Enhance your career with Salesforce training in Noida, featuring expert-led sessions and hands-on learning. Gain the skills and certification support needed to succeed with confidence..!

In Salesforce Metadata API, the CustomObject element is used to define custom objects, not fields. To add custom fields, you need to use the CustomField element instead of the CustomObject element when working with field definitions. Here’s how you can correct the structure:

  1. Ensure that your XML file targets the field creation process properly.
  2. Use the correct syntax for fields within an object, and ensure that the file structure correctly reflects the CustomObject and CustomField relationships.

Here’s a corrected version of your XML, which follows the correct approach for adding fields to the Case object:

<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
    <fullName>Case</fullName>
    <fields>
        <fullName>Net_Promoter_Score__c</fullName>
        <label>Net Promoter Score</label>
        <type>Number</type>
        <precision>2</precision>
        <scale>0</scale>
    </fields>
    <fields>
        <fullName>Product_Satisfaction__c</fullName>
        <label>Product Satisfaction</label>
        <type>Picklist</type>
        <picklist>
            <picklistValues>
                <fullName>Very Satisfied</fullName>
                <default>false</default>
            </picklistValues>
            <picklistValues>
                <fullName>Satisfied</fullName>
                <default>false</default>
            </picklistValues>
            <picklistValues>
                <fullName>Neutral</fullName>
                <default>false</default>
            </picklistValues>
        </picklist>
    </fields>
    <fields>
        <fullName>Service_Rating__c</fullName>
        <label>Service Rating</label>
        <type>Picklist</type>
        <picklist>
            <picklistValues>
                <fullName>Excellent</fullName>
                <default>false</default>
            </picklistValues>
            <picklistValues>
                <fullName>Good</fullName>
                <default>false</default>
            </picklistValues>
            <picklistValues>
                <fullName>Average</fullName>
                <default>false</default>
            </picklistValues>
        </picklist>
    </fields>
</CustomObject>

With this corrected structure, you should no longer face the error about not finding the declaration of the element CustomObject. The key takeaway is that the CustomField structure is required when adding fields to an existing Salesforce object.

Code Explanation:

In the corrected XML, the CustomObject element is used to define the Case object and its fields. The fields element within it specifies the new custom fields to be added. Each field is defined with the following components:

  • fullName: The name of the field (e.g., Net_Promoter_Score__c).
  • label: The label displayed for the field (e.g., Net Promoter Score).
  • type: The field type, such as Picklist or Number.
  • picklist: For picklist fields, the available picklist values are defined within the picklistValues tags.

This structure properly defines multiple fields for the Case object, ensuring they are added correctly without causing the “CustomObject” declaration error.

Why Choose Salesforce Training in Noida at CRS Info Solutions?

CRS Info Solutions offers a comprehensive  Salesforce Online Training program that caters to both beginners and professionals. This hands-on course combines practical scenarios with strong theoretical foundations, providing daily notes, interactive video tutorials, and thorough interview preparation. Gain the skills and confidence to pass Salesforce certifications and advance in the thriving CRM industry.

Known for excellence in Salesforce training in Noida, CRS Info Solutions covers a wide range of modules such as Admin, Developer, Integration, and Lightning Web Components (LWC). With expert instructors, the program blends theory with practical applications, ensuring you gain job-ready skills that align with industry demands. Designed for career growth, this training helps you meet employer expectations and thrive in today’s competitive job market.

Take the first step toward your Salesforce career by joining a free demo today and pave your way to professional success..!

Comments are closed.