0

Hello everybody I want to show a message inside a Lightning-modal and a link that redirects the user to a previously created record. Like for example:

enter image description here

The problem is that I am getting this: enter image description here

In my js I have this:

url;
wrapperC101({wrapperWithInfo : JSON.stringify(this.createWrapper()),recordIdPuntoSuministro: this.recordId }).then((result) =>{
        const{data,error} = result;
        this.data = result;
        console.log('data from apex function...'+ this.data);
        for (var iMessage of this.data){
            if(iMessage.includes('Error')){
                this.hayErrores = true;
                this.listErrors.push(iMessage);
                console.log('listErrors...'+ this.listErrors);
                /*
                    const notificationError = new ShowToastEvent({
                        title: 'Error',
                        message: iMessage,
                        variant: 'error'
                    });
                    this.dispatchEvent(notificationError);
                */
            }else{
                this.hayNuevoPasoMensajeria = true;
                this.recordIdPaso = iMessage;
                console.log('id del proceso mensajeria...'+ this.recordIdPaso);
                console.log('id del proceso mensajeria1...'+ iMessage);
                this.url = this[NavigationMixin.GenerateUrl]({
                    type: 'standard__recordPage',
                    attributes:{
                        recordId: this.recordIdPaso,
                        actionName: 'view',
                    }
                }).then(url =>{
                    console.log('url...' + this.url);
                    /*this.dispatchEvent(
                        new ShowToastEvent({                                
                            message: 'Proceso creado. {0}.',
                            messageData: [{
                                url,
                                label: 'Accede aqui.'
                            },],
                            variant: 'success',
                        })
                    )*/
                })
                
            }
        }
        this.error = undefined;
    }).catch((error)=>{

I think I am not catching correctly the url. Could anybody help me?

1 Answer 1

0

[NavigationMixin.GenerateUrl](pageReference) docs:

A component calls this API to get a promise that resolves to the resulting URL

That's why this.url = this[NavigationMixin.GenerateUrl] assign a promise to this.url. You should set it in the then() method:

this.recordIdPaso = iMessage;
this[NavigationMixin.GenerateUrl]({
    type: 'standard__recordPage',
    attributes:{
        recordId: this.recordIdPaso,
        actionName: 'view',
    }
}).then((url) => {
    this.url = url;
    console.log('url...' + this.url);
});

By the way, since it's a standard record page you could also set this.url as follow:

this.recordIdPaso = iMessage;
this.url = `/lightning/r/${this.recordIdPaso}/view`;

Then in template you should have something like:

<div>New record created. Click <a href={url}>here</a> to see it</div>

You must log in to answer this question.