• Johann03
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

Hi Everyone.

 

I've seen a few posts that are similar, but not the same as what i'm encountering. I've written a bulkified trigger (or at least i think I have), but when I load data in with dataloader, it does not appear that the trigger has fired when i open up the record.

 

If i click edit and save on the record, I can see the trigger has worked as it populates the fields as I expect it to. 

 

trigger code is below: 

 

trigger salesDataSellToCustomerTrigger on Sales_Data__c (before insert, before update) {

   Map<String, Sales_Data__c > salesDataMap = new Map<String, Sales_Data__c >();
   
   for (Sales_Data__c salesData: System.Trigger.new) { 
       
       if (salesData.Sell_to_Customer_No__c == null ) {
           salesData.Sell_to_Customer_Id__c = null;
       }
       else {
           salesDataMap.put(salesData.Sell_to_Customer_No__c, salesData);
       }
   }
    
   // Using a single database query, find all the accounts in 
   // the database that have the same Company No as any 
   // of the Sales Data with SellToCustomer Number
    
   for (Account account: [SELECT Id, Company_No__c FROM Account
                     WHERE Company_No__c IN :salesDataMap.KeySet()]) {
       Sales_Data__c sData = salesDataMap.get(account.Company_No__c);
       
       // update SalesData SellToCustomer ID
       sData.Sell_to_Customer_ID__c = account.id;
   }
}

Thought there may be an option in the data loader settings, but I couldn't see anything obvious, so any advice / guidence would be appreciated.

 

Jayson

  • August 16, 2012
  • Like
  • 0