function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jonathan Wolff 7Jonathan Wolff 7 

Datatable checkbox to mark tasks as completed

Hello, I would like to change my component datatable code so if the checkbox is checked the status of the task shown is marked as completed? Does somebody know how it can be made? If you like I share my code sample
Suraj Tripathi 47Suraj Tripathi 47
Hi,

You can follow the below code for your reference:-
public with sharing class TaskController {
    
    @AuraEnabled
    public static List < String > updateRecords(List < String > lstRecordId) {
        List < String > oErrorMsg = new List < String > ();
        List < Task > lstUpdate = [select Id,check_Box_field from Task where id IN: lstRecordId and check_Box_field=true];
        list<Task> toupdate = new list<task>();
        for(Task t: lstUpdate)
        {
          Task temp= new task();
            temp.Id=t.id;
            temp.Status='Completed';
        }

    Update   lstUpdate;

Please mark it as Best Answer if it helps you.

Thanks & Regards
Suraj Tripathi
Jonathan Wolff 7Jonathan Wolff 7
Hello Suraj, could you tell me how to implement it within my code?

COMPONENT

<aura:component controller="TaskController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    
    <aura:attribute name="recordId" type="Id" />    
    <aura:attribute name="tasks" type="Task[]"/>
    
    
                                             
    <aura:handler name="init" action="{!c.doInit}" value="{!this}"/> 
    <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>   
    <aura:attribute name="mycolumns" type="List"/> 
                                                 
    <lightning:card iconName="standard:task" title="Aufgaben">
        <div class="slds-card__body slds-card__body_inner">
             <div style="padding-left: 62%; margin-top: -2rem;">
            <lightning:button label="Aufgaben Anzeigen" onclick="{! c.openTask}"/>
            </div>
            
        </div>
    
        
  <div style= "font-size: 15px; font-weight: bold; margin-left:15px; margin-top:10px;">
      Überfällig        

  </div>
           
    <div>
        
        </div>    
        <div>
           
            <aura:if isTrue="{!not(empty(v.tasks))}">
                <lightning:datatable data="{!v.tasks }" 
                         columns="{!v.mycolumns }" 
                         keyField="Id"
                         hideCheckboxColumn="false"
                          
                                     />
                <aura:set attribute="else">
                    <div Style="text-align : center"> Keine Aufgaben</div>
                </aura:set>
            </aura:if>
        </div>
    </lightning:card>
     
</aura:component>

Javascript

({
    doInit: function(component, event, helper) {
        
    
            component.set('v.mycolumns', [
            {label: 'Thema', fieldName: 'SubjectName', type: 'url',
            typeAttributes: {label: { fieldName: 'Subject' }, target: '_blank'}},
                {label: 'Status', fieldName: 'Status', type: 'picklist', fixedWidth: 160 },
                
        ]);
        var action = component.get("c.loadTasks");
            action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                var records =response.getReturnValue();
                records.forEach(function(record){
                   
                    record.SubjectName = '/'+record.Id;
                    record.ActivityDate= record.ActivityDate;
        
       
                });
                component.set("v.tasks", records);
            }
                          
        });
        $A.enqueueAction(action);
                 
 },
    openTask: function(component, event, helper) {
       window.open('');
    
    },
          
      
   
})

APEX
   
public with sharing class TaskController {
     
//ÜBERFÄLLIG - Abfrage Tasks, wo das Activity Date abgelaufen und der Status "Not Completed" ist//
@AuraEnabled    
    public static List<Task> loadTasks(List<Id> recordId){
    string userId = UserInfo.getUserId();
    return[SELECT Subject, ActivityDate, Status  FROM Task WHERE ActivityDate< TODAY AND OwnerId=:userId AND Status !='Completed'];
}
}



 
            
Nabeel LateefNabeel Lateef
Keep up the good work, I read few posts on this web site and I conceive that your blog is very interesting and has sets of fantastic information. 
coffee printer (https://en.coffeecolorato.com/)