0

So I'm having an issue where MS teams invites are being sent to CASE queues for group meetings. This results in with a file being created which gets downloaded sometimes and sent to others.

  • The file that gets create in salesforce by MS Teams has no ics list in the file Extension field and doesn't add .ics to the end of the tile.
  • I can manually change the file Title field and add .ics to the end which allows the downloaded file to work properly.

I decide to take a stab at creating a trigger that would do this for me but haven't had luck.

What is incorrect about the below code? I don't get any errors when testing. however the name never changes. any help would be appreciated.

  trigger ContentVersionTrigger on ContentVersion (before insert) { 
    if(Trigger.isInsert && Trigger.IsBefore){ 
        for(ContentVersion cv: Trigger.new){ 
            Integer versionCount = 0; 
            versionCount = [SELECT count() FROM ContentVersion WHERE ContentDocumentId = :cv.Id]; 
            System.debug(versionCount); 
            if(versionCount <= 0){
                List<ContentDocument> contentDocList = [SELECT FileExtension FROM ContentDocument WHERE Id = :cv.ContentDocumentId];
                if(!contentDocList.isEmpty()){ 
                    String ext = contentDocList[0].FileExtension; 
                    if((ext == null) || (ext == '')){ 
                        cv.Title = cv.Title + '.ics'; 
                    } 
                    else if ( ext == 'ics'){
                        cv.Title = cv.Title + '.ics'; 
                    }
                }
            }
        }
    }
  }
1
  • 1
    ContentDocument doesn't yet exist on before Insert ContentVersion - you want to change the title in the ContentDocument
    – cropredy
    Feb 6 at 20:33

0

You must log in to answer this question.