• Rudix Niehaus
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies

Good day. I have implemented a lightning treeGrid comp to render a hierarchy of custom objects. Very similar to Accounts, the object has a lookup to itself. The JSON in the JS controller is correct when I view it in the console log. Am I missing something?

Aura comp:

<aura:attribute name="gridColumns" type="List" access="global" />
<aura:attribute name="gridData" type="Object" access="global" />

<lightning:treeGrid
                columns="{!v.gridColumns }"
               data="{!v.gridData }" 
               keyField="id" 
               aura:id="taskGrid" 
               /> 

JS Controller

component.set('v.gridColumns', [
            {label: 'Id', fieldName: 'Id', type: 'text'},
            {label: 'Name', fieldName: 'Name', type: 'text'},
            {label: 'Task Type', fieldName: 'Task_Type__c', type: 'text'},
            {label: 'Recurrence', fieldName: 'Recurrence__c', type: 'text'}
        ]);


var action = component.get('c.getTaskTree');

        action.setParams({
            "areaIds" : allSelections,
            "accountId" : accountId 
		});

        action.setCallback(this, function(response){

            var state = response.getState();

            if(state === 'SUCCESS'){
               
                console.log( response.getReturnValue() );

                component.set("v.gridData", response.getReturnValue());


Apex Controller

List<Task_Templates__c> taskList = [SELECT Id, Name, Task_Type__c, Recurrence__c 
                                            FROM Task_Templates__c 
                                            WHERE Functional_Area__c 
                                            IN :areaIds AND Parent_Task_Template__c = null];


        List<NodeClass> treeGrid = new List<NodeClass>();

        for(Task_Templates__c task :taskList){

            NodeClass node = new NodeClass();
            node.id = task.Id;
            node.name = task.Name;
            node.taskType = task.Task_Type__c;
            node.recurrence = task.Recurrence__c;

            node.children = buildTaskHierarchy(task.Id);

            treeGrid.add(node);

        }                                            
        
        String jsonStr = JSON.serialize(treeGrid);

        jsonStr = jsonStr.replaceAll('children', '_children');

        //return (NodeClass)JSON.deserialize(jsonStr , NodeClass.class);

        return jsonStr;
    }


    private static List<NodeClass> buildTaskHierarchy(Id parentId){

        List<Task_Templates__c> childTasks = [SELECT Id, Name, Task_Type__c, Recurrence__c 
                                FROM Task_Templates__c 
                                WHERE Parent_Task_Template__c = :parentId];

        List<NodeClass> childNodes = new List<NodeClass>();

        for(Task_Templates__c kid :childTasks){

            NodeClass childNode = new NodeClass();
            childNode.id = kid.Id;
            childNode.name = kid.Name;
            childNode.taskType = kid.Task_Type__c;
            childNode.recurrence = kid.Recurrence__c;

            childNode.children = buildTaskHierarchy(kid.Id);

            childNodes.add(childNode);

        }                        

        return childNodes;
    }

    public class NodeClass{

        @AuraEnabled
        public String id {get; set;}

        @AuraEnabled
        public String name {get; set;}

        @AuraEnabled
        public String taskType {get; set;}

        @AuraEnabled
        public String recurrence {get; set;}

        @AuraEnabled
        public List<NodeClass> children {get; set;}
         
    }


JSON as viewed in the console log when passing back from the Apex class to the JS controller

[
   {
      "taskType":"Internal",
      "recurrence":"Weekly",
      "name":"TASK A",
      "id":"a0E4K000000Vf7LUAS",
      "_children":[
         {
            "taskType":"Internal",
            "recurrence":"Bi-Weekly",
            "name":"TASK A1",
            "id":"a0E4K000000Vf7VUAS",
            "_children":[
               {
                  "taskType":"External",
                  "recurrence":"Quarterly",
                  "name":"TASK A1.1",
                  "id":"a0E4K000000Vf7aUAC",
                  "_children":[
                     
                  ]
               }
            ]
         }
      ]
   },
   {
      "taskType":"Internal",
      "recurrence":"Monthly",
      "name":"TASK B",
      "id":"a0E4K000000Vf7fUAC",
      "_children":[
         {
            "taskType":"External",
            "recurrence":"Annual",
            "name":"TASK B1",
            "id":"a0E4K000000Vf7kUAC",
            "_children":[
               
            ]
         }
      ]
   }
]
 

Thanks,

Rudolf

Good day.

I am trying to prevent users from deleting files they have uploaded via the Files related list on Cases. I want to add simple code in a trigger that will warn a user that he cannot delete Files linked to Cases. 

These files are stored as FeedItems that points to the ContentVersion and ContentDocument objects.
The issue that I have is that none of the triggers fires when a user deletes a File on cases. When you add a File via the related list upload button, 2 triggers fire (ContentVersion and ContentDocumentLink), but with a delete the before OR after delete events never executes.

Can anyone shed some light on this behaviour?

Thanks,
Rudolf Niehaus

Good day. I have implemented a lightning treeGrid comp to render a hierarchy of custom objects. Very similar to Accounts, the object has a lookup to itself. The JSON in the JS controller is correct when I view it in the console log. Am I missing something?

Aura comp:

<aura:attribute name="gridColumns" type="List" access="global" />
<aura:attribute name="gridData" type="Object" access="global" />

<lightning:treeGrid
                columns="{!v.gridColumns }"
               data="{!v.gridData }" 
               keyField="id" 
               aura:id="taskGrid" 
               /> 

JS Controller

component.set('v.gridColumns', [
            {label: 'Id', fieldName: 'Id', type: 'text'},
            {label: 'Name', fieldName: 'Name', type: 'text'},
            {label: 'Task Type', fieldName: 'Task_Type__c', type: 'text'},
            {label: 'Recurrence', fieldName: 'Recurrence__c', type: 'text'}
        ]);


var action = component.get('c.getTaskTree');

        action.setParams({
            "areaIds" : allSelections,
            "accountId" : accountId 
		});

        action.setCallback(this, function(response){

            var state = response.getState();

            if(state === 'SUCCESS'){
               
                console.log( response.getReturnValue() );

                component.set("v.gridData", response.getReturnValue());


Apex Controller

List<Task_Templates__c> taskList = [SELECT Id, Name, Task_Type__c, Recurrence__c 
                                            FROM Task_Templates__c 
                                            WHERE Functional_Area__c 
                                            IN :areaIds AND Parent_Task_Template__c = null];


        List<NodeClass> treeGrid = new List<NodeClass>();

        for(Task_Templates__c task :taskList){

            NodeClass node = new NodeClass();
            node.id = task.Id;
            node.name = task.Name;
            node.taskType = task.Task_Type__c;
            node.recurrence = task.Recurrence__c;

            node.children = buildTaskHierarchy(task.Id);

            treeGrid.add(node);

        }                                            
        
        String jsonStr = JSON.serialize(treeGrid);

        jsonStr = jsonStr.replaceAll('children', '_children');

        //return (NodeClass)JSON.deserialize(jsonStr , NodeClass.class);

        return jsonStr;
    }


    private static List<NodeClass> buildTaskHierarchy(Id parentId){

        List<Task_Templates__c> childTasks = [SELECT Id, Name, Task_Type__c, Recurrence__c 
                                FROM Task_Templates__c 
                                WHERE Parent_Task_Template__c = :parentId];

        List<NodeClass> childNodes = new List<NodeClass>();

        for(Task_Templates__c kid :childTasks){

            NodeClass childNode = new NodeClass();
            childNode.id = kid.Id;
            childNode.name = kid.Name;
            childNode.taskType = kid.Task_Type__c;
            childNode.recurrence = kid.Recurrence__c;

            childNode.children = buildTaskHierarchy(kid.Id);

            childNodes.add(childNode);

        }                        

        return childNodes;
    }

    public class NodeClass{

        @AuraEnabled
        public String id {get; set;}

        @AuraEnabled
        public String name {get; set;}

        @AuraEnabled
        public String taskType {get; set;}

        @AuraEnabled
        public String recurrence {get; set;}

        @AuraEnabled
        public List<NodeClass> children {get; set;}
         
    }


JSON as viewed in the console log when passing back from the Apex class to the JS controller

[
   {
      "taskType":"Internal",
      "recurrence":"Weekly",
      "name":"TASK A",
      "id":"a0E4K000000Vf7LUAS",
      "_children":[
         {
            "taskType":"Internal",
            "recurrence":"Bi-Weekly",
            "name":"TASK A1",
            "id":"a0E4K000000Vf7VUAS",
            "_children":[
               {
                  "taskType":"External",
                  "recurrence":"Quarterly",
                  "name":"TASK A1.1",
                  "id":"a0E4K000000Vf7aUAC",
                  "_children":[
                     
                  ]
               }
            ]
         }
      ]
   },
   {
      "taskType":"Internal",
      "recurrence":"Monthly",
      "name":"TASK B",
      "id":"a0E4K000000Vf7fUAC",
      "_children":[
         {
            "taskType":"External",
            "recurrence":"Annual",
            "name":"TASK B1",
            "id":"a0E4K000000Vf7kUAC",
            "_children":[
               
            ]
         }
      ]
   }
]
 

Thanks,

Rudolf