0

I am trying to call the class in my trigger that validates that only one of the custom fields must be populated and that custom fields cannot be empty. Below is my class and trigger, that shows of the error: Must specify the metadata file Please help me to resolve the issue!

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');
        }

        }
    }
}

TRIGGER:

trigger fieldNotEmpty on Property__c (before insert, before update, after insert) {

    Property__c[] prop = Trigger.new;

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

            FieldnotEmptycontrl.fieldNotEmpty(prop);



        }

    }
3
  • How are you producing this error? Are you attempting to deploy this code to a Salesforce org, and if so, how?
    – David Reed
    Commented Mar 22, 2020 at 23:42
  • There are several other problems with this code, including the wrong logical operator in the first if and attempting to operate on a static property (which is null) rather than the passed list, but error quoted sounds like a deployment problem.
    – David Reed
    Commented Mar 22, 2020 at 23:43
  • Here is what my Event Log is showing: 16:29 Validation Failed ERROR validating ApexTrigger triggers/fieldNotEmpty.trigger: Must specify the metadata file Commented Mar 22, 2020 at 23:52

1 Answer 1

0

"Must specify the metadata file" means that you're missing a file in your deployment. You should have a file called fieldNotEmpty.trigger-meta.xml in your deployment. See the docs for what the file should look like.

If you're using sfdx, consider using the sfdx force:apex:trigger:create command to make sure you generate the appropriate metadata file (and force:apex:class:create for Apex classes).

1
  • Thank you @sfdcfox! Got it! Commented Mar 24, 2020 at 2:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .