Tuesday, 17 November 2020

How to prepare test data for Content Document Link (File)?

 Hi,

Here we are going to learn how can we prepare test data for Content Document.

Let's take a scenario that when a File is inserted under an Account record then "Count of files" should be calculated. (Solution: Apex Trigger on ContentDocumentLink)

Then the following test class will be useful for testing the above scenario.

To insert Content Document Link object record we have to insert ContentVersion first then retrieve the 

ContentDocument and then insert ContentDocumentLink object record.

@isTest

private class ContentDocumentLinkActionsTest {     

    testmethod static void insertContentDocumentTest(){       

        Account actObj = new Account();

actObj.Name = 'Salesforce Techbook';

insert actObj;

        //start insert a filer under Account 

ContentVersion content=new ContentVersion();

content.Title='Header_Picture1';

content.PathOnClient='/' + content.Title + '.jpg';

Blob bodyBlob=Blob.valueOf('Unit Test ContentVersion Body');

content.VersionData=bodyBlob;

content.origin = 'H';

insert content;

List<ContentDocument> documentsObj = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument

  where LatestPublishedVersionId=:content.Id];

ContentDocumentLink contentlink=new ContentDocumentLink();

contentlink.LinkedEntityId=actObj.id;

contentlink.contentdocumentid=[select contentdocumentid from contentversion where id =: content.id].contentdocumentid;

contentlink.ShareType = 'V';

Test.startTest();

insert contentlink;       

        Test.stopTest();

    }

}



What is Granular locking?

 Hi,

Here let's see what is  Granular Locking Feature and its advantages.

Granular locking can help customers who experience locking issues("org" locks or lock errors). Without this feature, our code locks the entire table that keeps track of people’s membership in various groups. 

This means that any two administrative operations that change roles, public groups, or territories will conflict if they happen simultaneously. With granular locking, the code first analyses each operation and locks only the portions of the table touched by each. 

This makes it much less likely that any two group membership operations will conflict, and so customers who are using this feature will experience many fewer locks. In most cases, customers will find that with granular locking they can perform manual administration while automated update processes are running, and introduce some degree of multi-threading into integration code and other automated processes.

By default, granular locking is enabled, which allows some group maintenance operations to proceed simultaneously if there is no hierarchical or other relationship between the roles or groups involved in the updates. Administrators can adjust their maintenance processes and integration code to take advantage of this limited concurrency to process large-scale updates faster, all while still avoiding locking errors.

How can I tell if I should use granular locking?

     Customers who only occasionally receive an error message indicating that they have encountered a group membership lock are probably not good candidates for this feature. Customers should consider using this feature only if they experience frequent and persistent locking that severely restricts their ability to manage both manual and automated updates at the same time, or severely degrades the throughput of integrations or other automated group maintenance operations.

Advantages:

  • Groups that are in separate hierarchies are now able to be manipulated concurrently
  • Public groups and roles that do not include territories are no longer blocked by territory operations.
  • Users can be added concurrently to territories and public groups.
  • User provisioning can now occur in parallel.
    • Portal user creation requires locks only if new portal roles are being created. 
    • Provisioning new portal users in existing accounts occurs concurrently.
  •  A single-long running process, such as a role delete, blocks only a small subset of operations.

Reference:

https://help.salesforce.com/articleView?id=000325942&type=1&mode=1

https://developer.salesforce.com/docs/atlas.en-us.draes.meta/draes/draes_group_membership_locking.htm

https://developer.salesforce.com/docs/atlas.en-us.210.0.draes.meta/draes/draes_tools_granular_locking.htm

What’s the difference between Einstein Article Recommendations and Suggested Articles?

How Does Einstein Article Recommendations Work? Einstein Article Recommendations helps support agents resolve customer cases efficiently by ...