You need to sign in to do that
Don't have an account?

Help with Trigger on Attachments
I am trying to get the latest attachment id on to the case object fields based on the Name of the document . I have 2 fields on cases ( A,X)and If an attachement is added to case with the name ABC then its Id should be filled in Filed A on case and if Attachment is added with Name XYZ then Field X on the case should be filled with the ID of XYZ. If there are mutiple attachments with the same name then we should take the latest attachment.
I am trying this below way and it is able to bring in Att.Name or Att. ParentID but for some reason it could not bring in the Att.id field . And i still have to include by date condition
I am trying this below way and it is able to bring in Att.Name or Att. ParentID but for some reason it could not bring in the Att.id field . And i still have to include by date condition
trigger CaseAttachment on Attachment (before insert) { Boolean isCaseAttachment = FALSE; List<Case> Cases = new List<Case>(); Set<Id> accIds = new Set<Id>(); for(Attachment att : trigger.New){ /*Check if uploaded attachment is related to Case Attachment and same Case is already added*/ if(att.ParentId.getSobjectType() == Case.SobjectType && (!accIds.contains(att.ParentId)) && att.Name.contains('XYZ')){ //prepare a Case object for update Cases.add( new Case( Id=att.ParentId, A__c= att.ID ) ); //add the Caseid in set to eliminate dupe updates accIds.add(att.ParentId); } if(att.ParentId.getSobjectType() == Case.SobjectType && (!accIds.contains(att.ParentId)) && att.Name.contains('ABC')){ //prepare a Case object for update Cases.add( new Case( Id=att.ParentId, X__c = att.ID ) ); //add the Caseid in set to eliminate dupe updates accIds.add(att.ParentId); } } //finally update Cases update Cases; }

Got it to Working on Insert and Update , need help when a Delete operation occurs