Skip to main content
added 2 characters in body
Source Link
sanket kumar
  • 15.6k
  • 2
  • 29
  • 60

You can write trigger before delete on contentDocument.

you will get the ContentDocumentid from contentDocument in trigger.new.after that you need to fetch the opportunity id by querying the ContentDocumentLink as:- =[SELECT Id, LinkedEntityId, ContentDocumentId, Visibility, IsDeleted, ShareType,ContentDocument.Title, ContentDocument.createdDate, ContentDocument.FileType FROM ContentDocumentLink WHERE ContentDocumentId=:'your contentdocument id' and ContentDocument.FileType= 'SNOTE'];

[SELECT Id, LinkedEntityId, ContentDocumentId, Visibility, IsDeleted, ShareType,ContentDocument.Title, ContentDocument.createdDate, ContentDocument.FileType  FROM ContentDocumentLink WHERE ContentDocumentId=:'your contentdocument id' and ContentDocument.FileType= 'SNOTE']

this query will give you the List of Contentdocument which you have tried to delete. Now iterate it and store the LinkedEntityId in a set. The LinkedentityId is nothing but your opportunity id on which note is related with.

Now you can add logic to check for that opportunity and show error using add error method.

You can write trigger before delete on contentDocument.

you will get the ContentDocumentid from contentDocument in trigger.new.after that you need to fetch the opportunity id by querying the ContentDocumentLink as:- =[SELECT Id, LinkedEntityId, ContentDocumentId, Visibility, IsDeleted, ShareType,ContentDocument.Title, ContentDocument.createdDate, ContentDocument.FileType FROM ContentDocumentLink WHERE ContentDocumentId=:'your contentdocument id' and ContentDocument.FileType= 'SNOTE'];

this query will give you the List of Contentdocument which you have tried to delete. Now iterate it and store the LinkedEntityId in a set. The LinkedentityId is nothing but your opportunity id on which note is related with.

Now you can add logic to check for that opportunity and show error using add error method.

You can write trigger before delete on contentDocument.

you will get the ContentDocumentid from contentDocument in trigger.new.after that you need to fetch the opportunity id by querying the ContentDocumentLink as:-

[SELECT Id, LinkedEntityId, ContentDocumentId, Visibility, IsDeleted, ShareType,ContentDocument.Title, ContentDocument.createdDate, ContentDocument.FileType  FROM ContentDocumentLink WHERE ContentDocumentId=:'your contentdocument id' and ContentDocument.FileType= 'SNOTE']

this query will give you the List of Contentdocument which you have tried to delete. Now iterate it and store the LinkedEntityId in a set. The LinkedentityId is nothing but your opportunity id on which note is related with.

Now you can add logic to check for that opportunity and show error using add error method.

added 2 characters in body
Source Link
Sebastian Kessel
  • 13.2k
  • 12
  • 38
  • 61

You can write trigger before delete on contentDocument.

you will get the ContentDocumentid from contentDocument in trigger.new.after that you need to fetch the opportunity id by querying the ContentDocumentLink as:- =[SELECT Id, LinkedEntityId, ContentDocumentId, Visibility, IsDeleted, ShareType,ContentDocument.Title, ContentDocument.createdDate, ContentDocument.FileType FROM ContentDocumentLink WHERE ContentDocumentId=:'your contentdocument id' and ContentDocument.FileType= 'SNOTE'];=[SELECT Id, LinkedEntityId, ContentDocumentId, Visibility, IsDeleted, ShareType,ContentDocument.Title, ContentDocument.createdDate, ContentDocument.FileType FROM ContentDocumentLink WHERE ContentDocumentId=:'your contentdocument id' and ContentDocument.FileType= 'SNOTE'];

this query will give you the List of Contentdocument which you have tried to delete. Now iterate it and store the LinkedEntityId in a set. The LinkedentityId is nothing but your opportunity id on which note is related with.

Now you can add logic to check for that opportunity and show error using add error method.

You can write trigger before delete on contentDocument.

you will get the ContentDocumentid from contentDocument in trigger.new.after that you need to fetch the opportunity id by querying the ContentDocumentLink as:- =[SELECT Id, LinkedEntityId, ContentDocumentId, Visibility, IsDeleted, ShareType,ContentDocument.Title, ContentDocument.createdDate, ContentDocument.FileType FROM ContentDocumentLink WHERE ContentDocumentId=:'your contentdocument id' and ContentDocument.FileType= 'SNOTE'];

this query will give you the List of Contentdocument which you have tried to delete. Now iterate it and store the LinkedEntityId in a set. The LinkedentityId is nothing but your opportunity id on which note is related with.

Now you can add logic to check for that opportunity and show error using add error method.

You can write trigger before delete on contentDocument.

you will get the ContentDocumentid from contentDocument in trigger.new.after that you need to fetch the opportunity id by querying the ContentDocumentLink as:- =[SELECT Id, LinkedEntityId, ContentDocumentId, Visibility, IsDeleted, ShareType,ContentDocument.Title, ContentDocument.createdDate, ContentDocument.FileType FROM ContentDocumentLink WHERE ContentDocumentId=:'your contentdocument id' and ContentDocument.FileType= 'SNOTE'];

this query will give you the List of Contentdocument which you have tried to delete. Now iterate it and store the LinkedEntityId in a set. The LinkedentityId is nothing but your opportunity id on which note is related with.

Now you can add logic to check for that opportunity and show error using add error method.

Source Link
sanket kumar
  • 15.6k
  • 2
  • 29
  • 60

You can write trigger before delete on contentDocument.

you will get the ContentDocumentid from contentDocument in trigger.new.after that you need to fetch the opportunity id by querying the ContentDocumentLink as:- =[SELECT Id, LinkedEntityId, ContentDocumentId, Visibility, IsDeleted, ShareType,ContentDocument.Title, ContentDocument.createdDate, ContentDocument.FileType FROM ContentDocumentLink WHERE ContentDocumentId=:'your contentdocument id' and ContentDocument.FileType= 'SNOTE'];

this query will give you the List of Contentdocument which you have tried to delete. Now iterate it and store the LinkedEntityId in a set. The LinkedentityId is nothing but your opportunity id on which note is related with.

Now you can add logic to check for that opportunity and show error using add error method.