Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. trigger validate on Contact(before update){
  2. SET<String> ids = new SET<String>();
  3. for(contact c : trigger.new){
  4. ids.add(c.AccountId);
  5. }
  6. List<AggregateResult> tempAggr = [SELECT AccountId acc FROM Contact WHERE In_Use__c= true AND AccountId IN : ids GROUP BY AccountId];
  7.  
  8. Set<String> inUseset = new Set<String>();
  9. for(AggregateResult rs : tempAggr){
  10. inUseSet.add(String.valueOf(rs.get('acc')));
  11. }
  12.  
  13. for(contact c : trigger.new){
  14. if(inUseSet.contains(c.AccountId)){
  15.  
  16. c.adderror('In Use already used by another Contact');
  17. c.In_Use__c= false;
  18. }
  19. else{
  20.  
  21.  
  22. inUseSet.add(c.AccountId);
  23. }
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement