You need to sign in to do that
Don't have an account?
Maheshh Patel
RelatedContent on Opportunity
Hi Team,
On opportunity creation, I need to add a word document to related content related list.
I have written a trigger for the same and by reffering some blog to use contentdocumentlink.
But the document is being referenced in the Notes&attachment section instead of the RelatedContent.
Please find the below piece of code and give some insight...
Map<Id,ContentVersion> idToCvMap = new Map<Id,ContentVersion>([Select Id,ContentDocumentId from ContentVersion where Id IN: cvId]);
ContentDocumentLink cdl;
List<ContentDocumentLink> cdlLst = new List<ContentDocumentLink>();
for(Opportunity Opp: Trigger.New){
for(string str:idToCvMap.keyset()){
cdl = new ContentDocumentLink (LinkedEntityId=Opp.Id,ContentDocumentId= (idToCvMap.get(str)).ContentDocumentId,ShareType='V');
cdlLst.add(cdl);
idToCvMap.remove(str);
break;
}
}
insert cdlLst;
Thanks for the Info :)
On opportunity creation, I need to add a word document to related content related list.
I have written a trigger for the same and by reffering some blog to use contentdocumentlink.
But the document is being referenced in the Notes&attachment section instead of the RelatedContent.
Please find the below piece of code and give some insight...
Map<Id,ContentVersion> idToCvMap = new Map<Id,ContentVersion>([Select Id,ContentDocumentId from ContentVersion where Id IN: cvId]);
ContentDocumentLink cdl;
List<ContentDocumentLink> cdlLst = new List<ContentDocumentLink>();
for(Opportunity Opp: Trigger.New){
for(string str:idToCvMap.keyset()){
cdl = new ContentDocumentLink (LinkedEntityId=Opp.Id,ContentDocumentId= (idToCvMap.get(str)).ContentDocumentId,ShareType='V');
cdlLst.add(cdl);
idToCvMap.remove(str);
break;
}
}
insert cdlLst;
Thanks for the Info :)
Looking at your code seems to be fine. And also I did some researches trying to find out the issue. Unfortunatly I don't have an org with ContentDocument enabled, so I cannot test your code. However I would suggest you to start with something simpler, like this piece of code:
Execute it from Developer Console and check where it is created. Maybe the issue comes from the ContentNote instead of the way you create the ContentDocumentLink.
Hope this gives you some ideas.