• Marc De La Cruz
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
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 
 
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);
        }
   }
   

}


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

}