• Marmot74SFDC
  • NEWBIE
  • 0 Points
  • Member since 2009

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

Is there a way to disable Account Ownership change ability for everyone but Admins?

 

Mike 

Hey Guys, I have the following trigger that basically updates the account table when certain data criteria is met in a custom table. This is a one-many relationship and they relate via AccountId. It errors out with "Too many script statements: 50001". Please help with better logic.

trigger OnLicense_UpdateIsSupported on Licenses__c (after insert, after undelete, after update) { Set<String> AccountIDs = new Set<String>(); List<Account> updAccounts = new List<Account>(); for(Licenses__c Lic : trigger.new){ if(!AccountIDs.contains(Lic.Account__c)) AccountIDs.add(Lic.Account__c); } List<Account> Accounts = [SELECT ID, IsSupported__c, Is_Customer__c FROM Account WHERE ID IN :AccountIDs]; List<Licenses__c> lics = [SELECT Account__c, Expire_Date__c FROM Licenses__c WHERE Account__c IN :AccountIDs AND Active__c = true AND IsDeleted = false]; for(Account a : Accounts){ a.Is_Customer__c = false; a.IsSupported__c = false; for(Licenses__c l : lics){ if(l.Account__c == a.Id) { a.Is_Customer__c = true; if(l.Expire_Date__c >= Date.Today()) { a.IsSupported__c = true; } } } updAccounts.add(a); } update UpdAccounts; }