You need to sign in to do that
Don't have an account?

How to create an apex trigger that updates a record by subtracting from a sample request?
I am trying to create an apex trigger that subtracts the quantity from an inventory field of a custom object when the status of a seperate custom object's record's picklist is selected as shipped. I am new to apex programming and am not sure where to start.
Hi, it would be something like this:
I've recomend you learn about triggers in the Trigger module on Trailhead.
Anyway, based on your requirement, when you write a before trigger then you might not need any DML or LISTS inside the trigger since trigger by itself would change that record before insert or before update.
try using following trigger, In place of Custom_Object__c just write your object name.
And make sure the Status__c, inventory__c, and Quantity__c fields are same as yours. I mean their API names are same as yours.
If it solves the query then please mark it as Best Answer and it will help other people with similar issue!
Thank You sir!
Is the sol_sence_inventory__c and Quantity__c are both a NUMBER data type field? If yes, then are they both have decimal as 2 or 0?
Also let me know which line the error pops up in?
Anyway, I have just made a use of Integer.ValueOf() function inside the trigger. See if it works.