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
David JahnkeDavid Jahnke 

Simple Trigger to set "Authorization Required" checkbox.

Hi, First attempt at any kind of APEX trigger and could sure use some help.

On the object: gii__PurchaseOrder__c I display the realted list of line items that appear on the purchase order. These line items are displaying from: gii__PurchaseOrderLine__c which includes the field Product_Code__c and gii__Line_Gross_Amount__c.

I am looking for the code I need that will check to see IF any line has a Product_Code__c = 6410 or 1680 AND the gii__Line_Gross_Amount__c > $1000  then the Approval_Required__c field on the gii__PurchaseOrder__c page needs to be set to = TRUE.

Thanks in advance for any tips.
@anilbathula@@anilbathula@
Hi David Jahnke,

Try this code :-
 
trigger updateApprover on gii__PurchaseOrderLine__c (after insert,after update) {

            Set<id> giids=new Set<id>();
	   list<gii__PurchaseOrder__c> gpolst=new list<gii__PurchaseOrder__c>();
           
    
                     
            for(gii__PurchaseOrderLine__c gpl:Trigger.New){
                if(gpl.Product_Code__c!=null&& (gpl.Product_Code__c==6410||gpl.Product_Code__c==1680)  &&gpl.gii__Line_Gross_Amount__c >1000){                  
                    giids.add(gpl.gii__PurchaseOrder__c); //relationship field between both the objects
                                  
                }
            }            
                
    List<gii__PurchaseOrder__c> gpo=[select id,name,Approval_Required__c from gii__PurchaseOrder__c where id in:giids];
           if(!gpo.isEmpty()){
                for(gii__PurchaseOrder__c gp:gpo){                 
                    gp.Approval_Required__c=True;               
                    gpolst.add(gp);
                         
                }update gpolst;   
                
          }  
    }

Thanks
Anil.B