Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trigger validate on Contact(before update){
- SET<String> ids = new SET<String>();
- for(contact c : trigger.new){
- ids.add(c.AccountId);
- }
- List<AggregateResult> tempAggr = [SELECT AccountId acc FROM Contact WHERE In_Use__c= true AND AccountId IN : ids GROUP BY AccountId];
- Set<String> inUseset = new Set<String>();
- for(AggregateResult rs : tempAggr){
- inUseSet.add(String.valueOf(rs.get('acc')));
- }
- for(contact c : trigger.new){
- if(inUseSet.contains(c.AccountId)){
- c.adderror('In Use already used by another Contact');
- c.In_Use__c= false;
- }
- else{
- inUseSet.add(c.AccountId);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement