• Dhananjay123456789
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
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.
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;
}

 
I have custom object mycustobj__c
and in this object have custom field custfield__c  this null now
mycustobj__c contains 200+ records
requirment is to fill custfield__c such way that each record have serial no
ex- 1st record mm-01
      2nd record mm-02.

.......
and so on


Thanks for the input!....
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.
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;
}