function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
CBradley1985CBradley1985 

Simple Update Trigger

Hello,

 

I am very very new to Apex...And need some help so any help would be greatly appreciated!

 

I am trying to figure out how to write a trigger to do the job of a WFR. I would use a WFR but it won't update a field on a different object. 

 

What I'm trying to accomplish is when Inventory Reports__c on the Account record is equal to "None" it will update field Reports__c on my custom object "Inventory" to "Deactivate". 

 

Also, a point in the direction to help me on my learning path would be a great help!

 

Thank you,

 

Chris

bujjibujji
Hi,

Please check this trigger code.

trigger Update_Inventory on Inventory (before insert) {

system.debug('**************Trigger Fired********************');
List<Inventory> invNew = Trigger.new;
List<Inventory> invUpdate = new List<Inventory>();
List<Account> accNew = Trigger.new;
for(Account a: accNew)
{
if(a.Reports__c == 'None')
{
for(Inventory inv : invNew)
{
inv.Reports__c = 'Deactivate';
}
invUpdate.add(inv);
}
}
}

It will help your need.

Thanks,
Bujji