• William Roach-Barrette 5
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 0
    Replies
I have a group of users that we want to bring into salesforce and isolate using a role. The end goal is to give them access to records but unfortunately we DONT want them to have access to all the attached files asscoiated with that record. There will be times we want to manually share that file with this role but under normal circumstances we dont want them to have view permissions. Is there a way to do this easily? I am having trouble finding settings to limit file access based on profile 
I have group of user isolated by role who cant see all the files on a record visible to regular users. My management team has asked me to come up with a way to figure out how we can create a custom list of files related to an object that we can expose to these users. Ideally this would come with a way for regular users to add files to this list. I thought of creating a lightning comonent along with a custom list but maybe im over thinking it. is there a way to do this with related lists in a lightning page layout?
I am trying to create a lightning component that sits on a record and allows a user to create a note. The reason Im doing this is because my org needs to isolate a group of users by role and prevent them from seeing chatter. The idea is we use hashtage to convert chatter messages into notes (which already works.)

When an isolated user wants to post to chatter we want them to first add a note to the record. I was going to use the default “new Note” button baked into the related list but doing so invokes a menu with an auto-save option that makes using triggers a nightmare. So instead I used someone’s code (https://salesforce.stackexchange.com/questions/190502/lightning-components-how-to-invoke-new-note-panel-from-custom-components) to create a lightning component that would let my users post notes that are easier to monitor compared to the ContentDocumentLink and ContentVersions.

Here is where things get tricky. This is written as a modal component that needs to be triggered using a lightning action. The problem is lightning actions are stored on the Chatter feed lightning component, and in order to stop that we would need to disable feed tracking on the object this needs to work on (a non starter.)

So I converted the component as best as I could to use a simple row class to list the inputs and buttons. And now when I try to run my code I get the following error as the running user:

CUMULATIVE_PROFILING No profiling information for SOQL operations

Here is the Lightning component along with the controlling Apex class. 
New_Note.cmp
<aura:component controller="CreateNoteRecord" 
                implements="lightning:actionOverride,force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickActionWithoutHeader" 
                access="global" >
    <!-- Define Attribute-->
    <aura:attribute name="note" type="ContentNote" default="{'sobjectType': 'ContentNote','Title': '','Content': ''}"/>
    
    <div class="row">
        <h2 class = "header">Create New Note</h2>
        
        <b>Title:</b>
        <br/>
        <ui:inputText class="form-control" value="{!v.note.Title}"/>
        <br/>
        <b>Content:</b>
        <br/>
        <lightning:inputRichText value="{!v.note.Content}" placeholder="Type something interesting"/>
        <br/>
       
            <ui:button class="btn btn-default" press="{!c.create}">Create</ui:button>
            <ui:button class="btn btn-default" press="{!c.closeModel}">Cancel</ui:button>
      
        
        
    </div>

</aura:component>


New_NoteController.js
({
    create : function(component, event, helper) {
        //getting the candidate information
        var candidate = component.get("v.note");
        var noteContent = component.get("v.note.Content");
        //Calling the Apex Function
        var action = component.get("c.createRecord");
        //Setting the Apex Parameter
        action.setParams({
            nt : candidate,
            PrentId : component.get("v.recordId"),
            textConent : noteContent
           
            
        });
        //Setting the Callback
        action.setCallback(this,function(a){
            //get the response state
            var state = a.getState();
            //check if result is successfull
            if(state == "SUCCESS"){
                //Reset Form
                var newCandidate = {'sobjectType': 'ContentNote',
                                    'Title': '',
                                    'Content': ''
                                   };
                //resetting the Values in the form
                component.set("v.note",newCandidate);
            } else if(state == "ERROR"){
                alert('Error in calling server side action');
            }
        });
        var navEvt = $A.get("e.force:navigateToSObject");
        navEvt.setParams({
            "recordId": component.get("v.recordId"),
            "slideDevName": "detail"
        });
        navEvt.fire();
        $A.get('e.force:refreshView').fire();
        //adds the server-side action to the queue        
        $A.enqueueAction(action);
    },
    closeModel : function (component, event, helper) {
        var navEvt = $A.get("e.force:navigateToSObject");
        navEvt.setParams({
            "recordId": component.get("v.recordId"),
            "slideDevName": "detail"
        });
        navEvt.fire();
    }
})

CreateNewReord.apxc
public with sharing class CreateNoteRecord {
    @AuraEnabled
    public static void createRecord (ContentNote nt, id PrentId, String textConent){
        try{
            if(nt != null){
                insert nt;
                ContentDocument cd=[select id from ContentDocument where id=:nt.Id];
                textConent = textConent.replace('<p>', ' ');
                textConent = textConent.replace('</p>', ' ');
                textConent = textConent.replace('<br>' ,' ');
                ContentDocumentLink cdl=new ContentDocumentLink();
                System.debug('Text Preview: ' + textConent);
                cdl.ContentDocumentId=cd.id;
                cdl.LinkedEntityId=PrentId;
                cdl.ShareType='V';
                cdl.Visibility='AllUsers';
                FeedItem post = new FeedItem();
                post.ParentId = PrentId;
         		post.Body = textConent;
          		post.Title = nt.Title;
                insert cdl;
                insert post;
            }
        } catch (Exception ex){

        }
    }    
}


At this point im not sure what to do to get this working properly. Does anyone have a solution that might work for me?