• Singh 837
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
down vote favorite
I am trying to update a lookup field(Benefit_ID in Customer object) with the below code, The code works fine for single record but it is failing for multiple records:
Error: "caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, "
trigger updatelookupfield_Customer on Customer__c (before insert,before update) {
    Set<String> Bundle = new Set<String>();

    for (Customer__c Cust : Trigger.new) {
        Bundle.add(Cust.Bundle__c);
    }
List<Benfit__c> BenfitList = [SELECT id, Bundle__c FROM Benfit__c WHERE Bundle__c IN :Bundle];

    Map<String, Benfit__c> ASSIGN_BENEFIT = new Map<String, Benfit__c>();

    for (Benfit__c c : BenfitList) {
        ASSIGN_BENEFIT.put(c.Bundle__c, c);
    }

    for (Customer__c o : Trigger.new) {
              if (o.Bundle__c != null) {
            o.Benefit_ID__c = ASSIGN_BENEFIT.get(o.Bundle__c).id;
        }
        else {
            o.Benefit_ID__c = null;
        }
    }
    }
Just to highlight i am using multiple triggers on this object, not sure that is the reason for this issue.
 
We have a custom object "OrderItem__C". This custom object has a lookup field to standard contact object. It also has a field called "Shipping_customer_number__c".

We have this same field(Shipping_customer_number__c) in contact object too. Now when the user enters a shipping customer number in the order item object, based on the value in the shipping customer number field it should auto populate the contact lookup field.

This is because each contact record has an unique shipping customer number. I am trying different ways. Any insights can be helpful for us.

Thank you.