0

i create lwc component and i need prewiew files from ContentVersion. for this i create:

controller:

public with sharing class SendInvoiceService {
@AuraEnabled(cacheable=true)
public static List<ContentVersion> getPreview(id contentVId){
    return [SELECT Id, Title, FileExtension, ContentDocumentId From ContentVersion where id=:contentVId];
} }

html:

<template>
<lightning-card title="Send Invoice" >
<a onclick={navigateToFiles}>Navigate To Files</a>
</lightning-card>
</template>

js:

import { LightningElement, api, wire } from 'lwc';
import getInvoice from '@salesforce/apex/SendInvoiceService.getInvoice';
import NAME_FIELD from '@salesforce/schema/SendInvoice__c.FirstName__c';
import SUBJECT_FIELD from '@salesforce/schema/SendInvoice__c.Subject__c';
import EMAIL_FIELD from '@salesforce/schema/SendInvoice__c.Email__c';
import BODY_FIELD from '@salesforce/schema/SendInvoice__c.Body__c';
import { getSObjectValue } from '@salesforce/apex';
import { refreshApex } from '@salesforce/apex';

// importing navigation service
import { NavigationMixin } from 'lightning/navigation';

export default class sendInvoiceLWC extends NavigationMixin(LightningElement) {
@api recordId;
@api wiredContact;
@api realFormData;
@api InvoiceObj;
@wire(getInvoice, { oppId:'$recordId' }) fetchedInvoice( resp){
    this.wiredContact = resp;
    this.realFormData = this.wiredContact.data;
    this.InvoiceObj=resp;
}

get Subject() {
    return this.InvoiceObj.data?getSObjectValue(this.InvoiceObj.data,SUBJECT_FIELD,NAME_FIELD,EMAIL_FIELD,BODY_FIELD):'nothing';
}
  navigateToFiles() {
    this[NavigationMixin.Navigate]({
      type: 'standard__namedPage',
      attributes: {
          pageName: 'filePreview'
      },
      state : {
          selectedRecordId:'ContentDocumentId'
      }
    })
  }
}

when i click on my button i have error:

Unfortunately, there was a problem. Please try again. If the problem continues, get in touch with your administrator with the error ID shown here and any other related details. Error ID: 851152862-1216293 (-1143180353) Maybe i need to get import from my getPreview? and upgrate method when i use navigateToFiles?

1 Answer 1

1

You have to actually pass the content document id( 15 digit or 18 digit ) as selectedRecordId not 'ContentDocumentId' as a string.

You must log in to answer this question.