Ask Search:
Eva DeLorioEva DeLorio 

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.

Here is the main body of the trigger, it works to populate the related list: Content, but I need it to populate Related Content:

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'){
  
        tagN = String.valueOf(ot.Name);
       String searchquery='FIND\'' + tagN + '\'IN ALL FIELDS RETURNING ContentVersion(Id, ContentDocumentId)';
          
          List<List<ContentVersion>>searchList= search.query(searchquery);
          ContentVersion[] cv = ((List<ContentVersion>)searchList[0]);

             for(ContentVersion convers : cv){
             convers.Opportunity__c = o.id;
             update convers;
             } }}} }      



Thanks,
Eva DeLorio
Sunil KeshariSunil Keshari
You will get faster reponse if you post developer related questions to developer forum

http://boards.developerforce.com/sforce/?category.id=developers