• Pete111
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
I am new to salesforce development and have been trying to do cross-object updates. I have worked through numerous errors, and am now getting no errors. The code compiles and seems to run just fine. Except that its not doing what its supposed to do. In a test App that I created i have an "Attack" object. I have a custom field called "Hit or Miss" (In order to create an Attack you must select a Unit Object to attack) When the Hit or Miss field is = "HIT" then the status of the Unit Object should go to "Dead" The status is a picklist with values Dead or Alive. Hopefully I have explained enough so that you can understand what it is I am trying to do. Here is my code.

trigger statusTrigger on Attack__c (after insert) 
{
    for(Attack__c a : Trigger.New)
    {
        
        if(a.Hit_or_Miss__c =='HIT!')
        {   
            List<Unit_Type__c> unit = [SELECT Name,Status__c FROM Unit_Type__c WHERE Name = : 'a.Who_To_Attack__c'];
            for(Unit_Type__c u : unit)
            {
                u.Status__c = 'Dead';
                
            }
            update unit;
        }
        else
        {
            //Do Nothing.  
        }
        
    }
    
}

Can you see what im doing wrong?
I am new to salesforce development and have been trying to do cross-object updates. I have worked through numerous errors, and am now getting no errors. The code compiles and seems to run just fine. Except that its not doing what its supposed to do. In a test App that I created i have an "Attack" object. I have a custom field called "Hit or Miss" (In order to create an Attack you must select a Unit Object to attack) When the Hit or Miss field is = "HIT" then the status of the Unit Object should go to "Dead" The status is a picklist with values Dead or Alive. Hopefully I have explained enough so that you can understand what it is I am trying to do. Here is my code.

trigger statusTrigger on Attack__c (after insert) 
{
    for(Attack__c a : Trigger.New)
    {
        
        if(a.Hit_or_Miss__c =='HIT!')
        {   
            List<Unit_Type__c> unit = [SELECT Name,Status__c FROM Unit_Type__c WHERE Name = : 'a.Who_To_Attack__c'];
            for(Unit_Type__c u : unit)
            {
                u.Status__c = 'Dead';
                
            }
            update unit;
        }
        else
        {
            //Do Nothing.  
        }
        
    }
    
}

Can you see what im doing wrong?