function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
naveen reddy 19naveen reddy 19 

Field_Integrity_Exception, you cannot create a link for this type of entity through the api:Linked Entity ID:[LinkedEntity] Cannot_Insert_Update_Activate_Entity

Hi,

We have a trigger on ContentVersion, whenever a record is created and file attached to that record, this trigger will copy the file to another custom object record.
The file is loaded from ccScan tool and we facing below issue. Any help is really appreaciated.

User-added image 

 
Trigger ContentVersionTrigger(after update)
{
   ContentVersionHelper.onAfterUpdate(trigger.new);
}

public class ContentVersionHelper
{
    public void onAfterUpdate(list<ContentVersion> clst)
    {
        set<id> cdids=new set<id>();
        For(ContentVersion c:cLst)
        { 
            Cdids.add(c.ContentDocumentId);
        }
        List<ContentDocumentLink> cdlst=[select id,contentdocumentid, LinkedEntityId from ContentDocumentLink where contentdocumentid in:cdids];
        system.debug('#####cdlst='+cdlst);
        List<ContentDocumentLink> lst=new List<ContentDocumentLink>();
        set<id> csids=new set<id>();
        Map<Id,id> cseMap=new Map<id,id>();
        for(ContentDocumentLink cd:cdlst)
        {
            csids.add(cd.LinkedEntityId);
        }
        system.debug('#####csids='+csids);
        List<Case__c> caseLst=[select id,legacyid__c from case__c where legacyid__c=:csids];
        system.debug('#####caseLst='+caseLst);
        for(case__c c:caseLst)
        {
            cseMap.put(c.legacyid__c,c.id);
        }
        
        for(ContentDocumentLink cd:cdlst)
        {
            id myid=cd.LinkedEntityId;
            system.debug('#####myId='+myId);
            if(myId.getSObjectType().getDescribe().getName()=='ccScan__c')
            {
                             
                ContentDocumentLink cDe = new ContentDocumentLink();
                cDe.ContentDocumentId =cd.ContentDocumentId;
                system.debug('#####'+cseMap.get(cd.LinkedEntityId));
                cDe.LinkedEntityId = cseMap.get(cd.LinkedEntityId); 
                cDe.ShareType = 'V';
                cDe.Visibility = 'AllUsers';
                lst.add(cDe);
            }
            
        }
        insert lst;
        system.debug('#####lst='+lst);
    }
    
}

Thanks,
Naveen​
Best Answer chosen by naveen reddy 19
naveen reddy 19naveen reddy 19
Hi Addul,

Feed Tracking is already enabled for this object. 

Finally the issue is resolved. The problem is with the version of API. 
Need to use the API version 33 and later. Changed the API to latest and issue is not seen.

In API versions 33.0 and later, you can create and delete ContentDocumentLink objects with a LinkedEntityId of any record type that can be tracked in the feed, even if feed tracking is disabled for that record type.

 

All Answers

Abdul KhatriAbdul Khatri
Can you confirm if the custom object case__c has Feed Tracking Enabled (Setup | Customize | Chatter | FeedTracking)
naveen reddy 19naveen reddy 19
Hi Addul,

Feed Tracking is already enabled for this object. 

Finally the issue is resolved. The problem is with the version of API. 
Need to use the API version 33 and later. Changed the API to latest and issue is not seen.

In API versions 33.0 and later, you can create and delete ContentDocumentLink objects with a LinkedEntityId of any record type that can be tracked in the feed, even if feed tracking is disabled for that record type.

 
This was selected as the best answer
krishna23krishna23
Hi Naveen, Thanks for your answer.

Do we need to update api version latest to 33 or 33 to latest version please confirm I am a little bit confusing
naveen reddy 19naveen reddy 19
Hi Krishna,

API version must be greater than or equals to to 33. 
krishna23krishna23
Still, I am getting the same error after changing the API version. Is there any alternative solution for that.

Thanks!