• sfdc girlygeek
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
I tried but my code is not working
trigger AttachmentTrigger on Attachment (before insert) {
    Set<Id> attid = new Set<Id>();  
    for(Attachment att : Trigger.new){
        attid.add(att.parentId);
        
    }
    Map<Id,Account> acMap = new Map<Id,Account>([select id,(select id,parentId from attachments) from Account where Id IN : attid]);

    for(Attachment att : Trigger.New){
       
        if(acMap.get(att.parentId).attachments.size() > 4 ){
            
            att.adderror('You can not add more than 4 attachments!');
        }
    }
}

Can someone help me on this
I tried but my code is not working
trigger AttachmentTrigger on Attachment (before insert) {
    Set<Id> attid = new Set<Id>();  
    for(Attachment att : Trigger.new){
        attid.add(att.parentId);
        
    }
    Map<Id,Account> acMap = new Map<Id,Account>([select id,(select id,parentId from attachments) from Account where Id IN : attid]);

    for(Attachment att : Trigger.New){
       
        if(acMap.get(att.parentId).attachments.size() > 4 ){
            
            att.adderror('You can not add more than 4 attachments!');
        }
    }
}

Can someone help me on this