function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Adnan PAdnan P 

How to replace Attachments with Files in custom code

Hello,

We have some custom code that allows our users to add Attachments to a newly created Case. We are creating Cases via a customer controller and VF page. In Lightning Experience, Attachments are being replaced by Files.

Below is a snippet of code that we use to insert Attachments. Since Files is replacing Attachments does anyknow what I can use instead? In the future I would like to insert Files instead of Attachments.I can't find a File class in the SOAP API Developer Guide. Any feedback would be greatly appreciated!
 
public void insertAttachment() {
		try {
			insert new Attachment(ParentId = newCase.Id, OwnerId = UserInfo.getUserId(), Body = attachmentBody, Name = attachmentFilename);
			attachmentNameList.add(attachmentFilename);
			attachmentSuccess = true;
		} catch (DmlException e) {
			ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Error inserting attachment ' + attachmentFilename + ' to Case #' + caseNumber + '.\nError: ' + e.getMessage()));
			attachmentSuccess = false;
		}
	}