• George Laird 39
  • NEWBIE
  • 20 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 4
    Replies
Can someone help me with a report formula?  How can I get a net of the PAYMENT - REFUND for each payment type?   



User-added image
Hello All,

As you probably know, there is no way to run a report in Salesforce to show all files related to an object.  My client wants to run a report of all files that were uploaded to a custom object called POC__C.  They also want a link to the file directly in the report.  Ok, so I found a way to do this by making a custom object called FilesCopyCat__c.  This object doesn't hold files, just a link to them with a link to the related POC__record.  It works great!  I got the report I need by running a report type of POC's with Opporutnities and Files.  Since POCs are also realted to Opptys, I can run a report with the Oppty, then the POC, and get a list of all files with a link!  

BUT...how can I make this work with ALL objects, not just POC__C??  Please take a look at my trigger here and let me know if you have a way to make this work on all objects?  

Keep in mind, I have a field on this new FilesCopyCat object called "Related POC__c record."   I would want to replace this with just "related record." Or something.  This is where I need help. 



trigger FilesTrigger3 on ContentDocumentLink (after insert) {
    
    List<Files_CopyCat__c> ccs = new List<Files_CopyCat__c>();
    
    for (POC__c o: [SELECT Name, (SELECT ContentDocumentId, ContentDocument.Title, ContentDocument.ContentSize,ContentDocument.FileType 
                                  FROM ContentDocumentLinks 
                                  WHERE id IN: Trigger.new) 
                    FROM POC__c]) {
                        
                        for (ContentDocumentLink cdl: o.ContentDocumentLinks) {
                            
                            System.debug('Linked Document Id: ' + cdl.ContentDocumentId);
                            System.debug('Linked Document Title: ' + cdl.ContentDocument.Title);
                            System.debug('Linked Document Size: ' + cdl.ContentDocument.ContentSize);
                            
                            
                            Files_CopyCat__c f = new Files_CopyCat__c();
                            
                            f.Name = cdl.ContentDocument.Title;
                            f.File_Id__c = cdl.ContentDocumentId;
                            f.Related_POC__c = o.id;
                            f.File_Type__c = cdl.ContentDocument.FileType;
                            f.Link_To_File__c = URL.getSalesforceBaseUrl().toExternalForm() + '/' + cdl.ContentDocumentId;
                            
                            ccs.add(f);    
                            
                        }
                        
                        try{
                            insert ccs;    
                        } catch(DmlException e) {
                            system.debug('The following exception has occurred: ' + e.getMessage());
                        }
                        
                    }
}
I'm trying to create a class based on files, which is ContentDocument object.  I'm trying to create a map where the key is the ID of the ContentDocument and the value is a list of LinkedEntityId that are related to the key.  

I'm not sure how to do this.  I took a shot here but I don't think it's correct.  

I'm thinking that the key is correct, but I don't know how to get the values for each key.  Each key will have a few Ids for the value. 


***I'm passing a list called 'docs' from a trigger.  The list is essentially all of the docs that were passed from trigger.new


  public static void ProcessFiles(List<ContentDocument> docs){
        
Map<Id,List<ContentDocumentLink>> FilesMap = New Map<Id,List<ContentDocumentLink>>();
 
List<ContentDocumentLink> l = [SELECT LinkedEntityId FROM ContentDocumentLink WHERE ContentDocumentId IN : docs];


 
        for(ContentDocument c : docs){
            FilesMap.put(c.Id,l);
                
        }
        
    }  



Any help would be awesome!
Can someone help me with a report formula?  How can I get a net of the PAYMENT - REFUND for each payment type?   



User-added image
Can someone help me with a report formula?  How can I get a net of the PAYMENT - REFUND for each payment type?   



User-added image
I'm trying to create a class based on files, which is ContentDocument object.  I'm trying to create a map where the key is the ID of the ContentDocument and the value is a list of LinkedEntityId that are related to the key.  

I'm not sure how to do this.  I took a shot here but I don't think it's correct.  

I'm thinking that the key is correct, but I don't know how to get the values for each key.  Each key will have a few Ids for the value. 


***I'm passing a list called 'docs' from a trigger.  The list is essentially all of the docs that were passed from trigger.new


  public static void ProcessFiles(List<ContentDocument> docs){
        
Map<Id,List<ContentDocumentLink>> FilesMap = New Map<Id,List<ContentDocumentLink>>();
 
List<ContentDocumentLink> l = [SELECT LinkedEntityId FROM ContentDocumentLink WHERE ContentDocumentId IN : docs];


 
        for(ContentDocument c : docs){
            FilesMap.put(c.Id,l);
                
        }
        
    }  



Any help would be awesome!