You need to sign in to do that
Don't have an account?
Eva DeLoriol
How can I use Apex to populate the Related Content related list on Opportunities?
I've written a trigger that can find all content related to the Tags on an opportunity.
I have related the content to the Opportunity, but it shows up in the "Content" related list and not the "Related Content" related list where there are actions to deliver content.
I added Opportunity as a Field on the Content object to try and achieve the relationship, and I am getting results in the Content related list, but I really don't want it there, it needs to be in Related Content.
trigger opportunityTagContent on Opportunity (before insert, before update) { String tagN; for(Opportunity o: Trigger.new){ //get all tags for this opportunity list<OpportunityTag> list_tags = new list<OpportunityTag>(); for (OpportunityTag ot : [SELECT Id, Name, ItemId, Type FROM OpportunityTag WHERE ItemId = : o.Id]){ if(ot.Type == 'Public'){ // Create a new wrapper object tagN = String.valueOf(ot.Name); //now we should have a list of Opportunity Tags to work with System.debug('********** TAGN ' + tagN); String searchquery='FIND\'' + tagN + '\'IN ALL FIELDS RETURNING ContentVersion(Id, ContentDocumentId)'; List<List<ContentVersion>>searchList= search.query(searchquery); //ContentVersion[] is a list using searchList - first returned item in the searchQuery - id ContentVersion[] cv = ((List<ContentVersion>)searchList[0]); for(ContentVersion convers : cv){ convers.Opportunity__c = o.id; update convers; } } } } }
Thanks,
Eva