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
bpolbpol 

writing bulk trigger based on maps

I'm new, so I know I have the syntax wrong.  Any help with creating a bulk trigger would be greatly appreciated.

 

For each record that is inserted or updated, the trigger should

  • >review the field "Dept_Seg_1__c",
  • >lookup the mapped value "record_type__c" --- there is a map of Dept_Seg_1__c to record_type__c, and
  • >update the field "record_type__c" on all of the new/inserted records

 

Thanks!

 

Ben 

 

 

trigger UpdateLabor_Before on Labor__c (before insert, before update) {

//Create nested map of Labor ID TO Map of Record Type IDs TO Record Type Names
Map<ID,Map<String,String>> labortypeMap = new Map<ID,Map<String,String>> ();
Map<Dept_Seg_1__c,Record_Type__c> labortypeNestMap = new Map<String,String>
{'201' => 'mh center', '310' => 'staffing', '410' => 'sales',
'510' => 'marketing', '610' => 'training', '710' => 'it',
'810' => 'accounting & finance', '820' => 'hr',
'110' => 'call center', '411' => 'recruiting', '150' => 'coaching'};

for(Labor__c laborloop : trigger.new) {
labortypeMap.put(laborloop.id,
Dept_Seg_1__c,
labortypeNestMap.get(laborloop.Record_Type__c));

// Set records to values based on map
Labor__c labor = new Labor__c (Record_Type__c = labortypemap.get.(Record_Type__c));
Labor__c.add(labor);

}

upsert labor;

}

 

 

Message Edited by bpol on 02-22-2010 04:28 PM
jeffdonthemic2jeffdonthemic2

Ben,

 

You might want to check out the following blog post for help:

 

Writing Bulk Triggers for Salesforce.com

 

Jeff Douglas
Appirio, Inc.
http://blog.jeffdouglas.com 

bpolbpol

The post that helped a bit more was http://sfdc.arrowpointe.com/2008/09/13/bulkifying-a-trigger-an-example/

But both are good.

 

After much work, I was able to write a bulk trigger that works when I edit or update a new record.  The data updates are correct.

 

Interestingly -- it "works" when I bulk upload records; that is, it doesn't break.  However, the data is incorrect!!  When I edit any of these new records and re-save, it corrects itself.

 

Any thoughts?