• rsv
  • NEWBIE
  • 0 Points
  • Member since 2010

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

I am trying to pre-populate a custom lookup field on the Contact object with an account. This Account is the parent of the Account in the standard "Account Name" field on the Contact page. Facility is a child account, Practice is a parent account.

 

Here is what I have. It does not work - this is probably the 5th version of this trigger I have tried writing. I have logged a case with premier support - it has been escalated but I have not heard anything back.

 

Any Suggestions would be greatly appreciated.

trigger PopulatePracticeContact on Contact (before insert, before update) { //Set of Account Ids Set<Id> FacilityAccountIds = new Set<Id>(); for (Contact contactNew : Trigger.new) { //Facility Record Type == 012700000009R7G, always Child Account if(contactNew.Account.parentId != null && contactNew.Account.RecordTypeId == '012700000009R7G') { FacilityAccountIds.add(contactNew.AccountId); //A set of Facility Accounts } } Contact [] con = Trigger.new; con = [SELECT c.Id, c.Name, c.Related_Practice_Account__c, c.AccountId FROM Contact c WHERE c.AccountId IN :FacilityAccountIds]; Account [] pAccounts; pAccounts = [SELECT a.id, a.parentid, a.Name, (SELECT id, AccountId, Related_Practice_Account__c, Related_Practice__c FROM Contacts WHERE AccountId IN :FacilityAccountIds) FROM Account a WHERE a.id IN :FacilityAccountIds]; if(con.size()> 0){ if((con[0].AccountId == pAccounts[0].Id) && (pAccounts[0].ParentId != null)){ pAccounts[0].ParentId = con[0].Related_Practice_Account__c; } update con[0]; } }

 

  • August 19, 2009
  • Like
  • 0