You need to sign in to do that
Don't have an account?
Sam Lau
Attachment Trigger before delete to update record
Hi All,
I'm trying create a deletion trigger where I need to update two record attributes with attachment name and size. I'm still getting use to APEX, and had come across a few examples to help me with the following trigger. We're still utilizing the Attachment object as well. Any assistance would be appreciated. Currently I'm getting many errors on the SOQL query for TaskLst which I can't figure out at the moment. Thanks!
Sam
trigger AttachmentHCLTask on Attachment (before delete)
{
String tempParentId;
String tempAttName;
Integer tempAttSize;
Set<Id> setParentId = new Set<Id>();
List<BMCServiceDesk__Task__c> Tasklst = new List<BMCServiceDesk__Task__c>();
for (Attachment HCLTask : trigger.new ) {
tempParentId = HCLTask.Id;
tempAttName = HCLTask.Name;
tempAttSize = HCLTask.BodyLength;
if (tempParentId.left(10) =='a290H00000') {
System.debug('Debug : found a290H00000');
System.debug('Debug : Attachment id ' + HCLTask.Id );
setParentId.add(HCLTask.Id);
}
}
Tasklst = [select Id from BMCServiceDesk__Task__c where Id = setParentId AND HCL_Task_Creation_Sent__c = true];
For(BMCServiceDesk__Task__c e : Tasklst)
{
e.HCL_Attachment_Remove_File_Name__c = tempAttName;
e.HCL_Attachment_Remove_File_Size__c = tempAttSize;
}
update Tasklst;
}
I'm trying create a deletion trigger where I need to update two record attributes with attachment name and size. I'm still getting use to APEX, and had come across a few examples to help me with the following trigger. We're still utilizing the Attachment object as well. Any assistance would be appreciated. Currently I'm getting many errors on the SOQL query for TaskLst which I can't figure out at the moment. Thanks!
Sam
trigger AttachmentHCLTask on Attachment (before delete)
{
String tempParentId;
String tempAttName;
Integer tempAttSize;
Set<Id> setParentId = new Set<Id>();
List<BMCServiceDesk__Task__c> Tasklst = new List<BMCServiceDesk__Task__c>();
for (Attachment HCLTask : trigger.new ) {
tempParentId = HCLTask.Id;
tempAttName = HCLTask.Name;
tempAttSize = HCLTask.BodyLength;
if (tempParentId.left(10) =='a290H00000') {
System.debug('Debug : found a290H00000');
System.debug('Debug : Attachment id ' + HCLTask.Id );
setParentId.add(HCLTask.Id);
}
}
Tasklst = [select Id from BMCServiceDesk__Task__c where Id = setParentId AND HCL_Task_Creation_Sent__c = true];
For(BMCServiceDesk__Task__c e : Tasklst)
{
e.HCL_Attachment_Remove_File_Name__c = tempAttName;
e.HCL_Attachment_Remove_File_Size__c = tempAttSize;
}
update Tasklst;
}
Can you change your SOQL query as below and check.
you are query the id of the task object based on Atttachmentid. I dont think it is correct. What is the relation between Task object and Attachment object?
Thanks,