0

This is all on a Salesforce Community.

i have made lwc component where i want to remove record from knowledge article but it is showing null pointer exception. Firstly i am changing the owner and assigning to user who is log in/ performing task secondly removing the record... i cannot identify where exact issue is coming.

handleRowAction(event)
  {
    console.log('log inside')
    const actionName = event.detail.action.name;
    console.log('actionName: ', actionName)
    const row = event.detail.row;

    switch(actionName){
      case 'delete':
        this.deleteseletedrecord(row);
        break;

      case 'remove':
        this.updfileowner(row);
        this.removerecord(row);
        break;

      default:
    }
  }
updfileowner(currentRow)
  {
    const seletedRow = currentRow;
    console.log('seletedRow:' , seletedRow)

    updatefileowner({'fileIds': seletedRow.value})
    console.log("user updated successfully");
  }
removerecord(currentRow){
      const seletedRow = currentRow;
      console.log('seletedRow:' , seletedRow)

      //updatefileowner({'fileIds': seletedRow.value})
      //console.log("user updated successfully");

      removeSelectedfile({'recIds': seletedRow.value})
      .then(result => {
        this.dispatchEvent(
          new ShowToastEvent({
            title: 'Success',
            message: `Content Document Link ${seletedRow.label}  was deleted.`,
            variant: 'success',
          }),
        );
        //return refreshApex(this.fileList);
       //eval("$A. get('e. force:refreshView'). fire()");
       window.location.reload();
      })
      .catch(error => {
        this.message = undefined;
        this.error = error;
        this.dispatchEvent(
          new ShowToastEvent({
            title: 'Error creating records',
            message: error.body.pageError[0].message,
            variant: 'error',
          
          }),
        );
        console.log("error", JSON.stringify(this.error));
      });
    }

apex class

@AuraEnabled
public static String removeseletedrecord(String recIds){
        try{
            System.debug('inside apex class1');            
            System.debug('recIds : ' + recIds);
            List<ContentDocumentLink> fileRemoveList = [SELECT Id, ContentDocumentId, LinkedEntityId, ShareType FROM ContentDocumentLink WHERE ContentDocumentId = :recIds];            
            System.debug('fileRemoveList ' + fileRemoveList[0]);
            System.debug('fileRemoveList1 ' + fileRemoveList[1]);
            
            for(ContentDocumentLink cdl : fileRemoveList)
            {
                System.debug('current fileList: ' + cdl);
                if(cdl.ShareType == 'I')
                {
                    System.debug('inside if fileList: ' + cdl);
                    delete cdl;
                }
                System.debug('outside if fileList: ' + cdl);
            }
            
            return 'SUCCESS';
        }
        catch(Exception ex){
            throw new AuraHandledException(ex.getMessage());
        }
    }

@AuraEnabled
    public static void updateseletedrecordowner(Id fileIds){
        Id userId = userinfo.getUserId(); 
        System.debug('userId : ' + userId);
        
        List<ContentDocument> fileList = [Select id, title, filetype, parentid, ownerid from contentdocument where Id= :fileIds];
        System.debug('fileList' + fileList[0]);
        
        for(ContentDocument cd: fileList){
            cd.ownerid = userId;
        }
        update fileList;
        System.debug('update successfull' + fileList[0]);
    }

user is getting update successfully but when it comes in removerecord method and when it get record whoes share type is "I" it's unable to delete. common.apex.runtime.impl.DmlExecutionException: Delete failed. First exception on row 0 with id 06ABn000000g1MHMAY; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: []"

0

You must log in to answer this question.

Browse other questions tagged .