Thursday, October 18, 2018

What happen on Content Document Link if we upload Salesforce Files from record?

This entry specifically to know more about ContentDocumentLink which are not represented in diagram below.I happen to know more about this object after I experimenting on content's trigger(in future post).

To understand how the content relationship works please refer to diagram below .
 content objects diagram version 44.
refer to Salesforce for latest diagram

The highlight of this article is to identify ContentDocumentLink object that not appear in the diagram above.

ContentDocumentLink is Represents the link between a Salesforce CRM Content document or Salesforce file and where it's shared.
Field LabelAPI Field NameTypeLengthPrecisionScale
ContentDocumentLink IDIdid15
DocumentContentDocumentIdreference15
Is DeletedIsDeletedboolean
Linked EntityLinkedEntityIdreference15
Share TypeShareTypepicklist40
System ModstampSystemModstampdatetime
VisibilityVisibilitypicklist40
Experiment : Upload a file from Opportunity record.Once upload, click on the file and copy the id in URL. The id is represent contentdocumentid.Open Developer Console --> Execute Anonymous. Paste this code with contentdocumentid that you got.


1
2
3
system.debug('@@@ ContentVersion :  '+new List<ContentVersion> ([select Id ,ContentDocumentId from ContentVersion where ContentDocumentId ='06990000005Eor5']).size());
system.debug('@@@ ContentDocument :  '+new List<ContentDocument> ([select Id  from ContentDocument where Id ='06990000005Eor5']).size());
system.debug('@@@ ContentDocumentLink :  '+new List<ContentDocumentLink> ([select Id ,ContentDocumentId from ContentDocumentLink where ContentDocumentId ='06990000005Eor5']).size());

The result is like below, notice that we have two contentdocumentlink records.

To check what actually record being inserted in ContentDocumentLink, please run SOQL below:
select Id, ContentDocumentId, LinkedEntityId, IsDeleted, LinkedEntity.Type from ContentDocumentLink where ContentDocumentId ='06990000005Eor5' 
Result - LinkedEntity.Type are User (who upload the File) and Opportunity (the record where the file is uploaded)

Hope this will give you clear picture on what ContentDocumentLink object is doing.I am doing testing and find something interesting on content object which I will share with you later.

Happy coding

Tuesday, September 18, 2018

Dynamic Routing Approval

Use Case 

When Sales Rep submits Opportunity it requires different approver for different approval stage for different region.

Solution 

Create object to store approver details such for stage and region.Create Opportunity field to store approver for that particular Opportunity, these fields can be referred in Approval process. Using trigger query the approvers record and populate it in Opportunity based on specific criteria.

Meanwhile you can take a look in Appexchange, there an apps named Dynamic Approval Routing.

It is unmanaged package so we can view and modify the code to suit our need.The apps actually is a sample on how we can define approver for specific object.Its rule defined in the code and you might have different approver criteria and different object.The concept is

  1. to have one object to store approver details and
  2. create fields on object that going to be approved.
  3. create trigger on object that going to be approved to populate approver fields.
Design structure


Conclusion

Based on my experience especially for Opportunity object, I am still looking for alternative solution beside just create custom fields on Opportunity object because our Opportunity always hit custom fields limit.We do some clean up and at the end we have no more fields to create.

I am thinking maybe this can be solved using Queue to store Approver but it has limitation where it's not available for email response.There an idea for this here which still under threshold.

Do you face any issue related to this before? How you solve it?

Refer : Dynamic Approval Routing