You need to sign in to do that
Don't have an account?
Marc De La Cruz
return value from child object into error message
Hi,
I am trying to create an error message for a parent object that returns a value from the child object.
The objects I'm using are Asset and a custom object Asset_Assignment__c.
I can't seem to figure out how to return the value for the error message.
Any help would be appreciated.
Here's my code
I am trying to create an error message for a parent object that returns a value from the child object.
The objects I'm using are Asset and a custom object Asset_Assignment__c.
I can't seem to figure out how to return the value for the error message.
Any help would be appreciated.
Here's my code
trigger AssetAssignmentValidation on Asset (before update, before insert) { LIST <string> AssetList = NEW LIST <string>(); for(Asset a : Trigger.new){ if(a.Status == 'Available' && a.OwnerID != NULL){ AssetList.add(a.Name); List <Asset_Assignment__c> assignmentlist = [SELECT Name FROM Asset_Assignment__c WHERE Asset_Name__c in : AssetList]; for (Asset_Assignment__c aa : assignmentlist) { string assignmentnumber = ''; assignmentnumber = aa.name; return assignmentnumber; } a.adderror('Asset cannot be marked as available because it is currently assigned ' + 'Asset Assignment Number: ' + assignmentnumber); } } }
My understanding is if we are referencing fields in addError, they should be specified along with the object name ('c.LastName' as opposed to LastName). Please see example below
I would recommend assigning the value in the field 'assignmentnumber' to a value in a field in Asset. You can then use 'a.yourFieldName'
Anudeep
I'm trying to use the field from a custom child object that uses a lookup relationship for a trigger on the parent object.
What would be the best way to do that? I have no problem using a field on the asset object in the error message. I'm trying to use a field from a child object in an error message on the parent object.
Please verify/clarify these statements:
- You are not trying to add an error on a child object field.
- You are trying to reference the child object field name (not the value) in the error that you add to the parent object.
Thanks,
-Eric
It is possible to use a field from a child object in an error message on the parent object. Can you build a string like the example below and use in
addError method? Thanks
Anudeep