function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Asel Vazir 1Asel Vazir 1 

I need to call the trigger from the class that has a validation rule on custom fields

public with sharing class FieldnotEmptycontrl {

    public static Property__c field {get; set;}

    public FieldnotEmptycontrl(){
    field = new Property__c();

    }

    public static void fieldNotEmpty(List<Property__c> prop){

        if(field.Business__c == null || field.Contact__c == null){

            field.Business__c.addError('You must enter a value!');
            field.Contact__c.addError('You must enter a value!');

        if(field.Business__c != null && field.Contact__c != null){

            field.Business__c.addError('Cannot use two fields at the same time. Please choose only one field Business or Contact');
            field.Contact__c.addError('Cannot use two fields at the same time. Please choose only one field Business or Contact');
        }

        }
    }
}
Here is the Trigger calling the above class and method, but it shows the error • triggers/fieldNotEmpty.trigger: ERROR at line 1, column 1 - Must specify the metadata file 
trigger fieldNotEmpty on Property__c (before insert, before update, after insert) {

    if (Trigger.isBefore) {
        if(Trigger.isInsert){

            FieldnotEmptycontrl.fieldNotEmpty(Trigger.new);
          
        }
    }
}
Please help me to resolve the issue
 
Best Answer chosen by Asel Vazir 1
Andrew GAndrew G
In your IDE / Editor, there will generally be a filter for showing the .xml files related to your environment.  Turn it on and check that your class has an associated XML file:
illuminated cloud IDE showing list of classes with meta.xml files

Regards
Andrew
 

All Answers

Andrew GAndrew G
Seems you are missing a XML file for the deployment.
Was the trigger renamed?   Using your IDE/Editor, review if the Trigger has an associated XML file and that the file has the same name as the trigger.

Regards
andrew
 
Asel Vazir 1Asel Vazir 1
I am not deploying. I'm trying to call the class and method in my trigger and look like I've missed something in both codes, so trying to find out what exactly.
Andrew GAndrew G
In your IDE / Editor, there will generally be a filter for showing the .xml files related to your environment.  Turn it on and check that your class has an associated XML file:
illuminated cloud IDE showing list of classes with meta.xml files

Regards
Andrew
 
This was selected as the best answer
Asel Vazir 1Asel Vazir 1
Thank you Andrew, got it! Now it works :)