How can I make a pdf file available to Community users? Based on my searching, it sounds like I need to upload to Community via a Community license? I am not clear on exactly what I need to do
2 Answers
Solution that worked for me to be able to add a file to a custom object & Customer Community users can view it.
Triggr:
trigger ShareFiles2 on ContentDocumentLink (before insert) { for(ContentDocumentLink l:Trigger.new)l.Visibility='AllUsers'; }
Test for Trigger:
@isTest(seealldata=false)
private class TestSharedFiles2 {
static testMethod void TestSharedFiles2() {
//Create test tier level
Fee_and_Discount__c tier = new Fee_and_Discount__c(Begin_Date1__c=Date.valueOf('2008-01-01'), Type__c='Fee',
In_kind1__c=5.00, Cash1__c=5.00, Name='Tier 1');
insert tier;
//Create test account
Account acct = new Account(Name='Your Account Name',
recruitment_begin_date__c= Date.valueOf('2008-01-01'),
AccountSource='Website',
tier_level__c=tier.id,
recruitment_primary_contact__c='0056A000000zP7Z',
billingstate='North Carolina',
GC_Lottery_Winner__c=Date.valueOf('2018-01-01'),
TAC_Lottery_Winner__c=Date.valueOf('2018-01-01'),
priority__c='High');
insert acct;
ContentVersion contentVersion = new ContentVersion(
Title = 'Penguins',
PathOnClient = 'Penguins.jpg',
VersionData = Blob.valueOf('Test Content'),
IsMajorVersion = true
);
system.Test.startTest();
insert contentVersion;
List<ContentDocument> documents = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument];
//create ContentDocumentLink record
ContentDocumentLink cdl = New ContentDocumentLink();
cdl.LinkedEntityId = acct.id;
cdl.ContentDocumentId = documents[0].Id;
cdl.shareType = 'V';
insert cdl;
System.Test.stopTest();
}
}
Can you clarify that the all option is only for intermal and Community users. I cannot have the information available to the public. If the trigger is the answer I am going to work on that. I have not written one but now is the time to learn. Do you have a recommended webpage to learn this from?
-
Please use comments to add comments not answers. To learn how to create a trigger start with the trailhead module trailhead.salesforce.com/modules/apex_triggers though I would advise doing this one first trailhead.salesforce.com/modules/apex_database Commented Oct 20, 2017 at 11:54
-
I added a trigger to production that I thought should work to make new documents added to my Salesforce instance viewable by Customer Community users. This isn't happening. Can you provide guidance? trigger ShareFiles2 on ContentDocumentLink (before insert) { for(ContentDocumentLink l:Trigger.new)l.Visibility='AllUsers'; } Commented Oct 21, 2017 at 3:54
-
I am happy to report I got this to work. I can add files to a custom object & they are viewable by my Customer Community users. Thank you for the help. Commented Oct 21, 2017 at 4:44
???
,!!!
,...
, etc).