You need to sign in to do that
Don't have an account?
Dhananjay123456789
Apex trigger bulkification problem
custom objects
Associate__c
Product__c
Order__c
Associate__c(Lookup of Associate)
Order_Entry__c
Order__c (Lookup of Order__c)
Product__c (Lookup of Product__c)
Quantity__c (Number 5,0)
Inventory__c
Status__c (Picklist => 'Assigned', 'Ordered', 'Sold')
Associate__c (Lookup of Associate__c)
Product__c (Lookup of Product__c)
trigger:
Update Inventory to sold when Product or Quantity is changed on Order Entry.
Associate__c
Product__c
Order__c
Associate__c(Lookup of Associate)
Order_Entry__c
Order__c (Lookup of Order__c)
Product__c (Lookup of Product__c)
Quantity__c (Number 5,0)
Inventory__c
Status__c (Picklist => 'Assigned', 'Ordered', 'Sold')
Associate__c (Lookup of Associate__c)
Product__c (Lookup of Product__c)
trigger:
Update Inventory to sold when Product or Quantity is changed on Order Entry.
Get all Inventories which is related to Product and Status__c = 'Assigned' and Associate__c = Order.Associate__c and LIMIT = Quantity and update status to 'Sold' Order By CreatedDate LIMIT Quantity
trigger TriUpdateInventorySatus on Order_Entry__c (after update) { list<Id> ProductIdList = New List <Id>(); list<Id> AssociateIdList = New List <Id>(); Integer Quantity; List<Id> OrderIdList = new List<Id>(); List<Inventory__c> InventoryUpdation = new List<Inventory__c>(); for(Order_Entry__c OdEnRecord: trigger.new){ OrderIdList.add(OdEnRecord.Order__c); ProductIdList.add(OdEnRecord.Product__c); Quantity = Integer.valueOf(OdEnRecord.Quantity__c); } List<Order__c> OrderRecordList = [select id,name from Order__c where id IN: OrderIdList ]; For(Order__c OrderRecord: OrderRecordList){ AssociateIdList.add(OrderRecord.Associate__c); } List<Inventory__c> InventorySoqlList = [ select Id,Status__c from Inventory__c where Product__c In: ProductIdList AND Status__c ='Assigned' And Associate__c IN: AssociateIdList Order By CreatedDate LIMIT: Quantity ]; for(Inventory__c InventoryRecord: InventorySoqlList){ InventoryRecord.Status__c ='Sold'; InventoryUpdation.add(InventoryRecord); } update InventoryUpdation; }
Where are you stuck? Are you seeing any errors? Thanks
Thanks for replying
above code can't handle when bulk record going to update because the Quantity__c on the object Order_Entry__c is going to Inventory__c soql
As multiple record updated on Order_Entry__c object Quantity__c may have diffrent values thus for every record There should be new query...
Please Suggest Somthing