Skip to main content

Was anyone successful in getting their after insert trigger on Attachment working? i dontI don't see any debug logs for the trigger when iI try to invoke from the UI

trigger AttachmentTrigger on Attachment (after insert) { Map<id,List> taskAttachmentMap = new Map<id,List>(); for(Attachment attachment: [SELECT Body,BodyLength,ContentType,Description,Id,IsPrivate,Name,ParentId FROM Attachment where Id IN :Trigger.new]){
String text= String.valueof(attachment.ParentId); if(text.startswith('00T')){ List la = new List(); if(taskAttachmentMap.get(attachment.parentId)==null){ la.add(attachment); }else{ la = taskAttachmentMap.get(attachment.parentId); la.add(attachment); } taskAttachmentMap.put(attachment.parentId, la);
}

trigger AttachmentTrigger on Attachment (after insert) {
   Map<id,List<Attachment>> taskAttachmentMap = new Map<id,List<Attachment>>();
    for(Attachment attachment: [SELECT Body,BodyLength,ContentType,Description,Id,IsPrivate,Name,ParentId FROM Attachment where Id IN :Trigger.new]){           
        String text= String.valueof(attachment.ParentId);
        if(text.startswith('00T')){
            List<Attachment> la = new List<Attachment>();
            if(taskAttachmentMap.get(attachment.parentId)==null){
                la.add(attachment);
            }else{
                la = taskAttachmentMap.get(attachment.parentId);
                la.add(attachment);
            }
            taskAttachmentMap.put(attachment.parentId, la);                     
        }
         
    }
    
    List<Attachment> attachmentsToInsertonOpp = new List<Attachment>();
    //Find all tasks that are associated to opportunities
    if(taskAttachmentMap!=null){
        for(Task t: [select id, whatid from Task where id IN :taskAttachmentMap.keyset()]){
                String text1 = String.valueof(t.whatid);
                if(text1.startswith('006')){
                    for(Attachment att:taskAttachmentMap.get(t.id) ){
                        att.parentid=t.whatid;
                        attachmentsToInsertonOpp.add(att);                        
                    }
                }
        }           
        
    }
    
    //Now insert attachments
    if(attachmentsToInsertonOpp.size()!=0){
        insert attachmentsToInsertonOpp;
    }
    

}

}

Was anyone successful in getting their after insert trigger on Attachment working? i dont see any debug logs for the trigger when i try to invoke from UI

trigger AttachmentTrigger on Attachment (after insert) { Map<id,List> taskAttachmentMap = new Map<id,List>(); for(Attachment attachment: [SELECT Body,BodyLength,ContentType,Description,Id,IsPrivate,Name,ParentId FROM Attachment where Id IN :Trigger.new]){
String text= String.valueof(attachment.ParentId); if(text.startswith('00T')){ List la = new List(); if(taskAttachmentMap.get(attachment.parentId)==null){ la.add(attachment); }else{ la = taskAttachmentMap.get(attachment.parentId); la.add(attachment); } taskAttachmentMap.put(attachment.parentId, la);
}

    }
    
    List<Attachment> attachmentsToInsertonOpp = new List<Attachment>();
    //Find all tasks that are associated to opportunities
    if(taskAttachmentMap!=null){
        for(Task t: [select id, whatid from Task where id IN :taskAttachmentMap.keyset()]){
                String text1 = String.valueof(t.whatid);
                if(text1.startswith('006')){
                    for(Attachment att:taskAttachmentMap.get(t.id) ){
                        att.parentid=t.whatid;
                        attachmentsToInsertonOpp.add(att);                        
                    }
                }
        }           
        
    }
    
    //Now insert attachments
    if(attachmentsToInsertonOpp.size()!=0){
        insert attachmentsToInsertonOpp;
    }
    

}

Was anyone successful in getting their after insert trigger on Attachment working? I don't see any debug logs for the trigger when I try to invoke from the UI

trigger AttachmentTrigger on Attachment (after insert) {
   Map<id,List<Attachment>> taskAttachmentMap = new Map<id,List<Attachment>>();
    for(Attachment attachment: [SELECT Body,BodyLength,ContentType,Description,Id,IsPrivate,Name,ParentId FROM Attachment where Id IN :Trigger.new]){           
        String text= String.valueof(attachment.ParentId);
        if(text.startswith('00T')){
            List<Attachment> la = new List<Attachment>();
            if(taskAttachmentMap.get(attachment.parentId)==null){
                la.add(attachment);
            }else{
                la = taskAttachmentMap.get(attachment.parentId);
                la.add(attachment);
            }
            taskAttachmentMap.put(attachment.parentId, la);                     
        }
         
    }
    
    List<Attachment> attachmentsToInsertonOpp = new List<Attachment>();
    //Find all tasks that are associated to opportunities
    if(taskAttachmentMap!=null){
        for(Task t: [select id, whatid from Task where id IN :taskAttachmentMap.keyset()]){
                String text1 = String.valueof(t.whatid);
                if(text1.startswith('006')){
                    for(Attachment att:taskAttachmentMap.get(t.id) ){
                        att.parentid=t.whatid;
                        attachmentsToInsertonOpp.add(att);                        
                    }
                }
        }           
        
    }
    
    //Now insert attachments
    if(attachmentsToInsertonOpp.size()!=0){
        insert attachmentsToInsertonOpp;
    }
    

}
added 1782 characters in body
Source Link

Was anyone successful in getting their after insert trigger on Attachment working? i dont see any debug logs for the trigger when i try to invoke from UI

Updating post to add my code:

trigger AttachmentTrigger on Attachment (after insert) { Map<id,List> taskAttachmentMap = new Map<id,List>(); for(Attachment attachment: [SELECT Body,BodyLength,ContentType,Description,Id,IsPrivate,Name,ParentId FROM Attachment where Id IN :Trigger.new]){
String text= String.valueof(attachment.ParentId); if(text.startswith('00T')){ List la = new List(); if(taskAttachmentMap.get(attachment.parentId)==null){ la.add(attachment); }else{ la = taskAttachmentMap.get(attachment.parentId); la.add(attachment); } taskAttachmentMap.put(attachment.parentId, la);
}

    }
    
    List<Attachment> attachmentsToInsertonOpp = new List<Attachment>();
    //Find all tasks that are associated to opportunities
    if(taskAttachmentMap!=null){
        for(Task t: [select id, whatid from Task where id IN :taskAttachmentMap.keyset()]){
                String text1 = String.valueof(t.whatid);
                if(text1.startswith('006')){
                    for(Attachment att:taskAttachmentMap.get(t.id) ){
                        att.parentid=t.whatid;
                        attachmentsToInsertonOpp.add(att);                        
                    }
                }
        }           
        
    }
    
    //Now insert attachments
    if(attachmentsToInsertonOpp.size()!=0){
        insert attachmentsToInsertonOpp;
    }
    

}

Was anyone successful in getting their after insert trigger on Attachment working? i dont see any debug logs for the trigger when i try to invoke from UI

Was anyone successful in getting their after insert trigger on Attachment working? i dont see any debug logs for the trigger when i try to invoke from UI

Updating post to add my code:

trigger AttachmentTrigger on Attachment (after insert) { Map<id,List> taskAttachmentMap = new Map<id,List>(); for(Attachment attachment: [SELECT Body,BodyLength,ContentType,Description,Id,IsPrivate,Name,ParentId FROM Attachment where Id IN :Trigger.new]){
String text= String.valueof(attachment.ParentId); if(text.startswith('00T')){ List la = new List(); if(taskAttachmentMap.get(attachment.parentId)==null){ la.add(attachment); }else{ la = taskAttachmentMap.get(attachment.parentId); la.add(attachment); } taskAttachmentMap.put(attachment.parentId, la);
}

    }
    
    List<Attachment> attachmentsToInsertonOpp = new List<Attachment>();
    //Find all tasks that are associated to opportunities
    if(taskAttachmentMap!=null){
        for(Task t: [select id, whatid from Task where id IN :taskAttachmentMap.keyset()]){
                String text1 = String.valueof(t.whatid);
                if(text1.startswith('006')){
                    for(Attachment att:taskAttachmentMap.get(t.id) ){
                        att.parentid=t.whatid;
                        attachmentsToInsertonOpp.add(att);                        
                    }
                }
        }           
        
    }
    
    //Now insert attachments
    if(attachmentsToInsertonOpp.size()!=0){
        insert attachmentsToInsertonOpp;
    }
    

}

Source Link

After insert trigger on Attachment object doesnt fire

Was anyone successful in getting their after insert trigger on Attachment working? i dont see any debug logs for the trigger when i try to invoke from UI