• Naresh AV
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
Hi All,
I have an attachment with "Anyone with link" sharing configuration. How can I retrieve (or construct) the actual sharing URL using the apex code?
E.g., I have an attachment with id: 069240000009bdU and ViewAll permissionsI. From UI (web) I can see that its URL is:
https://ap1.salesforce.com/sfc/p/90000000t55g/a/90000000Chhk/fZcNyce65hRkHRM95T0nhPrJUNHiJ47If6BLyK24ixY
How can I get this URL through Apexcode and update to custom field?

Thanks in Advance.
Hi,

I need to add 'custom object' attachments to the chatter feed automatically. I have the following code but i'm facing some issues 

trigger AttachFileToCustomFeed on Attachment (after insert) {
 ID customId;
 list<FeedItem> listOfFeedFiles = new List<FeedItem>();
 if(Trigger.isAfter){
    for(Attachment attachment : trigger.new){
        string checkIfCase = string.valueof(attachment.Description); {
        customId= attachment.ParentId;
        FeedItem post = new FeedItem();
        post.ParentId = customId;
        post.Body = 'Attachment added';
        post.Type = 'ContentPost';
        post.ContentData = attachment.body;
        post.ContentFileName = attachment.Name;
        post.Title = attachment.Name; listOfFeedFiles.add(post);
     }
   } 
  }
  if(listOfFeedFiles!=null){
      insert listOfFeedFiles;
  }
}

but i'm gettiing the below error
'Invalid field ContentData for SObject FeedItem'
If I comment the 'ContentData' then i'm getting this
'Invalid field ContentFileName for SObject FeedItem'.
Can anyone please help in this issue.
Thanks in advance.
Hi All,
I have an attachment with "Anyone with link" sharing configuration. How can I retrieve (or construct) the actual sharing URL using the apex code?
E.g., I have an attachment with id: 069240000009bdU and ViewAll permissionsI. From UI (web) I can see that its URL is:
https://ap1.salesforce.com/sfc/p/90000000t55g/a/90000000Chhk/fZcNyce65hRkHRM95T0nhPrJUNHiJ47If6BLyK24ixY
How can I get this URL through Apexcode and update to custom field?

Thanks in Advance.
Hi,

I need to add 'custom object' attachments to the chatter feed automatically. I have the following code but i'm facing some issues 

trigger AttachFileToCustomFeed on Attachment (after insert) {
 ID customId;
 list<FeedItem> listOfFeedFiles = new List<FeedItem>();
 if(Trigger.isAfter){
    for(Attachment attachment : trigger.new){
        string checkIfCase = string.valueof(attachment.Description); {
        customId= attachment.ParentId;
        FeedItem post = new FeedItem();
        post.ParentId = customId;
        post.Body = 'Attachment added';
        post.Type = 'ContentPost';
        post.ContentData = attachment.body;
        post.ContentFileName = attachment.Name;
        post.Title = attachment.Name; listOfFeedFiles.add(post);
     }
   } 
  }
  if(listOfFeedFiles!=null){
      insert listOfFeedFiles;
  }
}

but i'm gettiing the below error
'Invalid field ContentData for SObject FeedItem'
If I comment the 'ContentData' then i'm getting this
'Invalid field ContentFileName for SObject FeedItem'.
Can anyone please help in this issue.
Thanks in advance.
I need to add account attachments to the chatter feed automatically. I have the following code which adds all attachments to the chatter feed, not just Account object attachments. How can I make it specific to the account object? Or make it specific to a file name?
 
trigger AttachFileToAccountFeed on Attachment (before insert) {   
    ID accountId; 
    list<FeedItem> listOfFeedFiles = new List<FeedItem>(); 
 
    if(Trigger.isBefore){
     
        for(Attachment attachment : trigger.new){
           string checkIfCase = string.valueof(attachment.Description);
          
           {
                //Adding a Content post
                accountId = attachment.ParentId;
                FeedItem post = new FeedItem();
                post.ParentId = accountId; //eg. Opportunity id, custom object id..
                post.Body = 'Attachment added';
                post.Type = 'ContentPost';
                post.ContentData = attachment.body;
                post.ContentFileName = attachment.Name;
                post.Title = attachment.Name;
                listOfFeedFiles.add(post);         
           }
        }
    }
     
    if(listOfFeedFiles!=null){
        insert listOfFeedFiles;
    }  
     
}