• Priyanshu gupta
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Hi,
I have a trigger on Attachment which prevents the user from deletingior updating the attachment if the parent custom Object Inventory status is marked as 'Final'. we are switching to lightning so I cant use Attachment anymore since they cant add attachments from the page. how can i write the same logic using Content file, how do i get the parent id?
Here is the logic of Attachment trigger:

Schema.DescribeSObjectResult inv = Inventory_Exception__c.sObjectType.getDescribe();
String invKeyPrefix = inv.getKeyPrefix();
if(trigger.isUpdate){
        for(Attachment a :trigger.new){
            if(invKeyPrefix == String.valueOf(a.parentId).left(3) &&
               [select status__c from Inventory_Exception__c where id = :a.parentId].status__c =='Final'){
                   a.adderror('This attachment could not be modified because this exception record is marked as Final.');
               }
        }


    if(trigger.isDelete){
        for(Attachment a :trigger.old){
            if(invKeyPrefix == String.valueOf(a.parentId).left(3) &&
               [select status__c from Inventory_Exception__c where id = :a.parentId].status__c =='Final'){
                   a.adderror('This attachment could not be deleted because this exception record is marked as Final.');
               }
        }
Hi ,

Can some one help me to write a trigger to prevent delete of all Account records and its supporting test class.
Doesn't matter who the user is (Sys Admin/Custom Profile/Read Only...etc), the user should not be able to delete the account record.
There cannot be any exception.

Any help is appreciate.
Thanks!
A