ABSYZ ABSYZ

  • Home

    Home

  • About us

    Who We Are

  • Our Expertise

    What we Do

  • Our Approach

    How We Do It

  • Products

    What We Made

  • Industries

    Who We Do It For

  • Clients

    Whom We Did It For.

  • Article & Blogs

    What Experts Think

  • Careers

    Join The Team

  • Get In Touch

    Let’s Get Started

ABSYZ

Migrating to Salesforce Files

Home / Article & Blogs / Salesforce / Migrating to Salesforce Files
By adityamoro inSalesforce

With the upcoming Winter ’18 release of Salesforce, the option for uploading files and attachments to the Notes and Attachments related list is going to get scrapped. With the ‘Attach File’ button being done away with, users will not be able to upload to attachments, but will only be able to view existing ones.

img1

Users fortunately, will still have the option to upload files to Salesforce which can be viewed and downloaded from the Files related list.
So, what’s the difference? Shifting to files from attachments looks like a straight switch and, in some ways it still is. However, navigating to the same as a developer can be a little tricky. Let us look at some key differences between the Attachment and ContentVersion(for files) sObjects.

ContentVersion, ContentDocument & ContentDocumentLink

Many aspects of Salesforce files are controlled by multiple objects that include ContentVersion, ContentDocument, ContentDocumentFeed and ContentDocumentHistory and ContentDocumentLink. Here we need to look at the ones required for basic operations such as inserting, tracking and deleting files. The document being uploaded gets saved in the form of ContentDocument record. ContentVersion represents the current version of the document whereas ContentDocumentLink represents the link between the document and the record to which it is being attached.

Tracking your Files

img2

Suppose there are multiple attachments under an Account record, which you want to compile into a list. If you have the Account record id, here’s how you generally do it.

[sourcecode language=”java”]List<Attachment> attachlist = [Select id, Name, Body from Attachment where ParentId =: Account.id];[/sourcecode]

However, ContentVersion has no lookup field to its parent record. Sure, you can go ahead and create a lookup field, but this will have to be done for all Objects supporting Files in the Org. Here, we refer to the ContentVersion files via ContentDocumentLink. ContentDocumentLInk acts as the link between Content Document and where it is shared. This two-step process requires us first to query all records of ContentDocumentLink under the particular Account record.

[sourcecode language=”java”]List<ContentDocumentLink> cdlist = [Select id, LinkedEntityId, ContentDocumentID from ContentDocumentLink where LinkedEntityId =: Acc.id];[/sourcecode]

The LinkedEntityID is the ID of the linked object and plays the same role as ParentId does in Attachment object. Once we have executed the above query, we retrieve the Content Documents via the ContentDocumentID.
Use a set of type IDs and add the ContentDocumentId to that set.

[sourcecode language=”java”]Set<Id> fileId = new Set<Id> ();
for(ContentDocumentLink cl:cdlist){
fileId.add(cl.ContentDocumentId);
}
List<ContentVersion> cvlist = [Select Id, Title from ContentVersion where ContentDocumentId in:fileId order by CreatedDate DESC];[/sourcecode]

The list cvlist holds all the files attached to that particular Account record.
Similarly, if you have to insert files from a visualforce page, once you have inserted the files, don’t forget to link the files using ContentDocumentLink, else they won’t show up on the record page under the related list!

Deleting your Files

Suppose you want to start fresh and delete all the existing files under an Account, again the process is not straightforward as Salesforce does not allow delete DML directly on ContentVersion object. For more details, refer the link:
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_contentversion.htm#sforce_api_objects_contentversion

So, here’s how you do it.

[sourcecode language=”java”]List<ContentDocument> listtodelete = [Select id from ContentDocument where id in:fileId];
if (listtodelete.size ()> 0){
delete listtodelete ;
}
[/sourcecode]

ContentDocument object represents any document that has been uploaded to Salesforce Files. Remember, we are not just removing the link here, but the file itself. Hence, we use ContentDocument object here.

After the Winter’18 release, Attachments though still existing, Salesforce Files will be where all the action will be. So, If you haven’t migrated to files yet, there’s no time like now!

Files
76
Like this post
2 Posts
adityamoro

Search Posts

Archives

Categories

Recent posts

BioAsia 2023 in Hyderabad: An Annual International Event

BioAsia 2023 in Hyderabad: An Annual International Event

The Role Of Marketing in Small & Medium Enterprises

The Role Of Marketing in Small & Medium Enterprises

Salesforce For Retail: How Salesforce CRM Can Help Retailers

Salesforce For Retail: How Salesforce CRM Can Help Retailers

What is ChatGPT & How Does It Work?

What is ChatGPT & How Does It Work?

What Is Graphic Design? (Executive Summary 2023)

What Is Graphic Design? (Executive Summary 2023)

  • Previous PostMarketing Cloud Getting Started program
  • Next PostLogin to Salesforce from Facebook using Graph API

Related Posts

Salesforce For Retail: How Salesforce CRM Can Help Retailers
Salesforce

Salesforce For Retail: How Salesforce CRM Can Help Retailers

Introduction To Copado Devops Tool
Salesforce

Introduction To Copado Devops Tool

What is Salesforce Code Builder?
Salesforce

What is Salesforce Code Builder?

Automation in Healthcare And Its Benefits
Health Cloud Salesforce

Automation in Healthcare And Its Benefits

Leave a Reply (Cancel reply)

Your email address will not be published. Required fields are marked *

*
*

ABSYZ Logo

INDIA | USA | UAE

  • About us
  • Article & Blogs
  • Careers
  • Get In Touch
  • Our Expertise
  • Our Approach
  • Products
  • Industries
  • Clients
  • White Papers

Copyright ©2022 Absyz Inc. All Rights Reserved.

youngsoft
Copy
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “ACCEPT ALL”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent. Privacy Policy
Cookie SettingsREJECT ALLACCEPT ALL
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled

Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.

CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.

Functional

Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.

Performance

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

Analytics

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.

Advertisement

Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.

Others

Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.

SAVE & ACCEPT