• tamir
  • NEWBIE
  • 0 Points
  • Member since 2009

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

I'm trying to update the record type of my contacts based on the change of the record type on the account. I figured out how to have it update the contacts on an account record type change - but only to one fixed record record type. I realize it's not best practice to hard code ID's, but I'll tackle that part if i figure this out - and it's even possible...

 

Here's what I have so far.. 

 

 

trigger UpdateContactsOnRecordTypeChange on Account (before update) { Map<Id, Account> acctsWithNewRecordType = new Map<Id, Account>(); for (Integer i = 0; i < Trigger.new.size(); i++) { if ( (Trigger.old[i].RecordTypeId != Trigger.new[i].RecordTypeId)) { acctsWithNewRecordType.put(Trigger.old[i].id, Trigger.new[i]); } } List<Contact> updatedContacts = new List<Contact>(); for (Contact c : [SELECT id, RecordTypeId, accountId FROM Contact WHERE AccountId in :acctsWithNewRecordType.keySet()]) {Account parentAccount = acctsWithNewRecordType.get(c.accountId); c.RecordTypeId = '012000000008QwA'; updatedContacts.add(c); } update updatedContacts; }

 I tried replacing the:

 

c.RecordTypeId = '012000000008QwA';

with: 

 

 

if (Trigger.new[i].RecordTypeId != '012000000008Qw1') {c.RecordTypeId = '012000000008QwF'};

 

 

to accomplish this:


(Trigger.new[i].RecordTypeId != '012000000008Qw1') then c.RecordTypeId = '012000000008QwF'
(Trigger.new[i].RecordTypeId != '012000000008Qw0') then c.RecordTypeId = '012000000008QwA'
(Trigger.new[i].RecordTypeId != '012000000008Qvv') then c.RecordTypeId = '012000000008Qw5'

 

 

But to no avail...

 

Any help would be appreciated.

 

Thanks, Chris

 

 

 

 

 

  • February 11, 2009
  • Like
  • 0