2

I deployed a trigger and trying to update all records to populate custom field of existing records with value ( account object ). Everything works perfect unless I get the following error:

System.DmlException: Update failed. First exception on row 2017 with id *; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Domain__c]: [Domain__c]

Explanation is simple, Domain__c field is required at every account. But this account ( which triggered error ) doesn't have this field populated... so:

  1. How is that possible to have this account in salesforce?
  2. Obviously all updates/changes of this account ( e.g. using integrated 3rd party software ) will trigger error ( all update trigger )... How to fix it?
  3. What condition to add ( in apex code ) to skip these records in mass update?
2
  • 2
    Most likely that Account existed before the required Domain__c field was added. Sep 16 '14 at 20:25
  • @DanielBallinger that is right, I had same thing in mind, I thought there was kind of validation before field was added.
    – NGix
    Sep 16 '14 at 20:42
6

1. How is that possible to have this account in salesforce?

A few possibilities. The field may not have always have been required, or the field may not have always been present. So records could have existed in your DB either before this field was created, or after it was created and prior to it being set to required.

2. Obviously all updates/changes of this account ( e.g. using integrated 3rd party software ) will trigger error ( all update trigger )... How to fix it?

You have a few options. You can run a report of all records without this field populated and try to fill them in to ensure all your records have this field. You could also try to use a validation rule or some validation in your trigger itself, instead of making the field required at the field level. This way you can make the field required in certain scenarios and not required in other. I would suggest just trying to rectify the data issue (records without the field populated), rather than coding around it though.

3. What condition to add to skip these records in mass update?

Really the same answer as number 2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.