You need to sign in to do that
Don't have an account?
chikku
I need apex class to get ContentDocumentLink field
Hi all,
I need an apex class to get a standard object called documentlink field called LinkedEntityId.
when document upload. It should automatically create a task.
This my code:
trigger CreateTask on ContentVersion (after insert)
{
List<Task> insertTask = new List<Task>();
Task newTask = new Task();
for(ContentVersion newCase : Trigger.new)
{
newTask.subject = 'Document Expiration';
newTask.ActivityDate = newCase.Expiry_Date__c;
newTask.ownerId = newCase.OwnerId;
newTask.status = 'Not started';
newTask.Priority = 'Normal';
if('ObjAPiName' == 'Contact')
{
newTask.WhoId = //Contact ;
}
else
{
newTask.WhatId =[select LinkedEntityId from ContentDocumentLink where ContentDocumentId IN : newCase.ContentDocumentId].Id; // this code I impletement to get LinkedEntityId from ContentDocumentLink
}
insert newTask;
if(insertTask.isEmpty())
{
try{
}catch(DmlException de)
{
System.debug(de);
}
}
}
}
I need to assign LinkedEntityId this id to create task.
Trigger -> WhoId.
Is anyone help?
Thanks in advance.
I need an apex class to get a standard object called documentlink field called LinkedEntityId.
when document upload. It should automatically create a task.
This my code:
trigger CreateTask on ContentVersion (after insert)
{
List<Task> insertTask = new List<Task>();
Task newTask = new Task();
for(ContentVersion newCase : Trigger.new)
{
newTask.subject = 'Document Expiration';
newTask.ActivityDate = newCase.Expiry_Date__c;
newTask.ownerId = newCase.OwnerId;
newTask.status = 'Not started';
newTask.Priority = 'Normal';
if('ObjAPiName' == 'Contact')
{
newTask.WhoId = //Contact ;
}
else
{
newTask.WhatId =[select LinkedEntityId from ContentDocumentLink where ContentDocumentId IN : newCase.ContentDocumentId].Id; // this code I impletement to get LinkedEntityId from ContentDocumentLink
}
insert newTask;
if(insertTask.isEmpty())
{
try{
}catch(DmlException de)
{
System.debug(de);
}
}
}
}
I need to assign LinkedEntityId this id to create task.
Trigger -> WhoId.
Is anyone help?
Thanks in advance.
Please execute the following line of code:
newTask.WhatId =[select LinkedEntityId from ContentDocumentLink where ContentDocumentId =: newCase.ContentDocumentId].LinkedEntityId;
I hope you find the above solution helpful. If it does, please mark it as Best Answer to help others too.
Thanks and Regards,
Sachin Arora
www.sachinsf.com