2

I got an issue rendering my data using WRAPPER class.

Here is my SyntheseComponent.cls :

public with sharing class SyntheseController {
    // Permet de compter le nombre de contact pour la page account
    @AuraEnabled(Cacheable=true)
    public static Integer getContact(String accId) {
        AggregateResult[] groupedResults = [SELECT COUNT(Name)contact FROM Contact WHERE AccountId = :accId];
        Integer countContact = (Integer)groupedResults[0].get('contact');
        return countContact;
    }
    // Permet de compter le nombre d'opportunité pour un Compte
    @AuraEnabled(Cacheable=true)
    public static Integer getOpportunity(String accId) {
        AggregateResult[] groupedResults = [SELECT COUNT(Name)opportunity FROM Opportunity WHERE AccountId = :accId];
        Integer countOpportunity = (Integer)groupedResults[0].get('opportunity');
        return countOpportunity;
    }

    // Permet de récuperer la date de la dernière opportunitée de type B2B crée
    @AuraEnabled(Cacheable=true)
    public static String getLastCreatedOpportunity(String accId) {
        AggregateResult[] groupedResults = [SELECT MAX(CreatedDate)lastCreatedOpportunity FROM Opportunity WHERE AccountId = :accId];
        Datetime lastCreatedOpportunity = (Datetime)groupedResults[0].get('lastCreatedOpportunity');
        String lastCreatedOpportunityFormated = lastCreatedOpportunity.format('dd/MM/yyyy');
        return lastCreatedOpportunityFormated;
    }

    // Permet de compter le nombre d'opportunité de type B2B pour un Compte
    @AuraEnabled(Cacheable=true)
    public static Integer getOpportunityB2B(String accId) {
        AggregateResult[] groupedResults = [SELECT COUNT(Name)opportunityB2B FROM Opportunity WHERE AccountId = :accId AND Is_B2B__c = true];
        Integer countOpportunityB2B = (Integer)groupedResults[0].get('opportunityB2B');
        return countOpportunityB2B;
    }
    // Permet de récuperer la date de la dernière opportunitée de type B2B crée
    @AuraEnabled(Cacheable=true)
    public static String getLastCreatedOpportunityB2B(String accId) {
        AggregateResult[] groupedResults = [SELECT MAX(CreatedDate)lastCreatedOpportunityB2B  FROM Opportunity WHERE AccountId = :accId AND Is_B2B__c = true];
        Datetime lastCreatedOpportunityB2B = (Datetime)groupedResults[0].get('lastCreatedOpportunityB2B');
        String lastCreatedOpportunityB2BFormated = lastCreatedOpportunityB2B.format('dd/MM/yyyy');
        return lastCreatedOpportunityB2BFormated;
    }
    // Permet de compter le nombre d'opportunité B2B Abonnement pour un Compte
    @AuraEnabled(Cacheable=true)
    public static Integer getOpportunityB2BAbonnement(String accId) {
        AggregateResult[] groupedResults = [SELECT COUNT(Name)opportunityB2BAbo FROM Opportunity WHERE AccountId = :accId AND Is_B2B__c = true AND ROLLUP_Duree_abonnement__c != null];
        Integer countOpportunityB2BAbo = (Integer)groupedResults[0].get('opportunityB2BAbo');
        return countOpportunityB2BAbo;
    }
    // Permet de compter le nombre d'opportunité B2B Places Sèches pour un Compte
    @AuraEnabled(Cacheable=true)
    public static Integer getOpportunityB2BPlacesSeches(String accId) {
        AggregateResult[] groupedResults = [SELECT COUNT(Name)opportunityB2BPlacesSeches FROM Opportunity WHERE AccountId = :accId AND Is_B2B__c = true AND ROLLUP_Duree_abonnement__c = null];
        Integer countOpportunityB2BPlacesSeches = (Integer)groupedResults[0].get('opportunityB2BPlacesSeches');
        return countOpportunityB2BPlacesSeches;
    }
    // Permet de calculer le montat des opportunités B2B
    @AuraEnabled(Cacheable=true)
    public static Decimal getOpportunityB2BAmount(String accId) {
        AggregateResult[] groupedResults = [SELECT SUM(Amount)opportunityB2BAmount FROM Opportunity WHERE AccountId = :accId AND Is_B2B__c = true];
        Decimal amountOpportunityB2B = (Decimal)groupedResults[0].get('opportunityB2BAmount');
        return amountOpportunityB2B;
    }
    // Permet de calculer le montat des opportunités B2B pour les Abonnements
    @AuraEnabled(Cacheable=true)
    public static Decimal getOpportunityB2BAboAmount(String accId) {
        AggregateResult[] groupedResults = [SELECT SUM(Amount)opportunityB2BAmount FROM Opportunity WHERE AccountId = :accId AND Is_B2B__c = true AND ROLLUP_Duree_abonnement__c != null];
        Decimal amountOpportunityB2B = (Decimal)groupedResults[0].get('opportunityB2BAmount');
        return amountOpportunityB2B;
    }
    // Permet de calculer le montat des opportunités B2B pour les Places Sèches
    @AuraEnabled(Cacheable=true)
    public static Decimal getOpportunityB2BPlacesSechesAmount(String accId) {
        AggregateResult[] groupedResults = [SELECT SUM(Amount)opportunityB2BPlacesSechesAmount FROM Opportunity WHERE AccountId = :accId AND Is_B2B__c = true AND ROLLUP_Duree_abonnement__c = null];
        Decimal amountOpportunityB2BPlacesSeches = (Decimal)groupedResults[0].get('opportunityB2BPlacesSechesAmount');
        return amountOpportunityB2BPlacesSeches;
    }
    // Permet de calculer le montant de toutes les opportunités pour un compte
    @AuraEnabled(Cacheable=true)
    public static Decimal getOpportunityAmount(String accId) {
        AggregateResult[] groupedResults = [SELECT SUM(Amount)opportunityAmount FROM Opportunity WHERE AccountId = :accId];
        Decimal amountOpportunity = (Decimal)groupedResults[0].get('opportunityAmount');
        return amountOpportunity;
    }
    // Permet de compter le nombre d'opportunité de type Event pour un Compte
    @AuraEnabled(Cacheable=true)
    public static Integer getOpportunityEvent(String accId) {
        AggregateResult[] groupedResults = [SELECT COUNT(Name)opportunityEvent FROM Opportunity WHERE AccountId = :accId AND Is_event__c = true];
        Integer countOpportunityEvent = (Integer)groupedResults[0].get('opportunityEvent');
        return countOpportunityEvent;
    }
    // Permet de calculer le montant des opportunités de type Event
    @AuraEnabled(Cacheable=true)
    public static Decimal getOpportunityEventAmount(String accId) {
        AggregateResult[] groupedResults = [SELECT SUM(Amount)opportunityEventAmount FROM Opportunity WHERE AccountId = :accId AND Is_event__c = true];
        Decimal amountOpportunityEvent = (Decimal)groupedResults[0].get('opportunityEventAmount');
        return amountOpportunityEvent;
    }
    // Permet de récuperer la date de la dernière opportunitée de type Even crée
    @AuraEnabled(Cacheable=true)
    public static String getLastCreatedOpportunityEvent(String accId) {
        AggregateResult[] groupedResults = [SELECT MAX(CreatedDate)lastCreatedOpportunityEvent  FROM Opportunity WHERE AccountId = :accId AND Is_event__c = true];
        Datetime lastCreatedOpportunityEvent = (Datetime)groupedResults[0].get('lastCreatedOpportunityEvent');
        String lastCreatedOpportunityEventFormated = lastCreatedOpportunityEvent.format('dd/MM/yyyy');
        return lastCreatedOpportunityEventFormated;
    }
    // Permet de compter le nombre d'opportunité de type Lagardère pour un Compte
    @AuraEnabled(Cacheable=true)
    public static Integer getOpportunityLagardere(String accId) {
        AggregateResult[] groupedResults = [SELECT COUNT(Name)opportunityLagardere FROM Opportunity WHERE AccountId = :accId AND Is_Lagardere__c = true];
        Integer countOpportunityLagardere = (Integer)groupedResults[0].get('opportunityLagardere');
        return countOpportunityLagardere;
    }
    // Permet de calculer le montant des opportunités de type Lagardère
    @AuraEnabled(Cacheable=true)
    public static Decimal getOpportunityLagardereAmount(String accId) {
        AggregateResult[] groupedResults = [SELECT SUM(Amount)opportunityLagardereAmount FROM Opportunity WHERE AccountId = :accId AND Is_Lagardere__c = true];
        Decimal amountOpportunityLagardere = (Decimal)groupedResults[0].get('opportunityLagardereAmount');
        return amountOpportunityLagardere;
    }
    // Permet de récuperer la date de la dernière opportunitée de type Lagardère crée
    @AuraEnabled(Cacheable=true)
    public static String getLastCreatedOpportunityLagardere(String accId) {
        AggregateResult[] groupedResults = [SELECT MAX(CreatedDate)lastCreatedOpportunityLagardere  FROM Opportunity WHERE AccountId = :accId AND Is_Lagardere__c = true];
        Datetime lastCreatedOpportunityLagardere = (Datetime)groupedResults[0].get('lastCreatedOpportunityLagardere');
        String lastCreatedOpportunityLagardereFormated = lastCreatedOpportunityLagardere.format('dd/MM/yyyy');
        return lastCreatedOpportunityLagardereFormated;
    }
    // Permet de compter les activités en cours pour le Compte
    @AuraEnabled(Cacheable=true)
    public static Integer getOpenActivities(String accId) {
        AggregateResult[] groupedResults = [SELECT COUNT(Subject)openactivities FROM Task WHERE AccountId = :accId];
        Integer countOpenactivities = (Integer)groupedResults[0].get('openactivities');
        return countOpenactivities;
    }

    public class SyntheseData {
        @AuraEnabled
            public Integer countContact {get; set;}
            @AuraEnabled
            public Integer countOpportunity {get; set;}
            @AuraEnabled
            public String lastCreatedOpportunityFormated {get; set;}
            @AuraEnabled
            public Integer countOpportunityB2B {get; set;}
            @AuraEnabled
            public String lastCreatedOpportunityB2BFormated {get; set;}
            @AuraEnabled
            public Integer countOpportunityB2BAbo {get; set;}
            @AuraEnabled
            public Integer countOpportunityB2BPlacesSeches {get; set;}
            @AuraEnabled
            public Decimal amountOpportunityB2BPlacesSeches {get; set;}
            @AuraEnabled
            public Decimal amountOpportunityB2B {get; set;}
            @AuraEnabled
            public Decimal amountOpportunity {get; set;}
            @AuraEnabled
            public Integer countOpportunityEvent {get; set;}
            @AuraEnabled
            public Decimal amountOpportunityEvent {get; set;}
            @AuraEnabled
            public String lastCreatedOpportunityEventFormated {get; set;}
            @AuraEnabled
            public Integer countOpportunityLagardere {get; set;}
            @AuraEnabled
            public Decimal amountOpportunityLagardere {get; set;}
            @AuraEnabled
            public String lastCreatedOpportunityLagardereFormated {get; set;}
            @AuraEnabled
            public Integer countOpenactivities {get; set;}

            public SyntheseData(Integer countContact, Integer countOpportunity, String lastCreatedOpportunityFormated, Integer countOpportunityB2B, String lastCreatedOpportunityB2BFormated,
            Integer countOpportunityB2BAbo, Integer countOpportunityB2BPlacesSeches, Decimal amountOpportunityB2BPlacesSeches, Decimal amountOpportunityB2B, Decimal amountOpportunity, Integer countOpportunityEvent,
            Decimal amountOpportunityEvent, String lastCreatedOpportunityEventFormated, Integer countOpportunityLagardere, Decimal amountOpportunityLagardere, String lastCreatedOpportunityLagardereFormated,
            Integer countOpenactivities) {
                this.countContact = countContact;
                this.countOpportunity = countOpportunity;
                this.lastCreatedOpportunityFormated = lastCreatedOpportunityFormated;
                this.countOpportunityB2B = countOpportunityB2B;
                this.lastCreatedOpportunityB2BFormated = lastCreatedOpportunityB2BFormated;
                this.countOpportunityB2BAbo = countOpportunityB2BAbo;
                this.countOpportunityB2BPlacesSeches = countOpportunityB2BPlacesSeches;
                this.amountOpportunityB2BPlacesSeches = amountOpportunityB2BPlacesSeches;
                this.amountOpportunityB2B = amountOpportunityB2B;
                this.amountOpportunity = amountOpportunity;
                this.countOpportunityEvent = countOpportunityEvent;
                this.amountOpportunityEvent = amountOpportunityEvent;
                this.lastCreatedOpportunityEventFormated = lastCreatedOpportunityEventFormated;
                this.countOpportunityLagardere = countOpportunityLagardere;
                this.amountOpportunityLagardere = amountOpportunityLagardere;
                this.lastCreatedOpportunityLagardereFormated = lastCreatedOpportunityLagardereFormated;
                this.countOpenactivities = countOpenactivities;
            }
    }

    @AuraEnabled(Cacheable=true)
    public static SyntheseData getSyntheseData(Id accId){
        Integer countContact = getContact(accId);
        Integer countOpportunity = getOpportunity(accId);
        String lastCreatedOpportunityFormated = getLastCreatedOpportunity(accId);
        Integer countOpportunityB2B = getOpportunityB2B(accId);
        String lastCreatedOpportunityB2BFormated = getLastCreatedOpportunityB2B(accId);
        Integer countOpportunityB2BAbo = getOpportunityB2BAbonnement(accId);
        Integer countOpportunityB2BPlacesSeches = getOpportunityB2BPlacesSeches(accId);
        Decimal amountOpportunityB2BPlacesSeches = getOpportunityB2BPlacesSechesAmount(accId);
        Decimal amountOpportunityB2B = getOpportunityB2BAmount(accId);
        Decimal amountOpportunity = getOpportunityAmount(accId);
        Integer countOpportunityEvent = getOpportunityEvent(accId);
        Decimal amountOpportunityEvent = getOpportunityEventAmount(accId);
        String lastCreatedOpportunityEventFormated = getLastCreatedOpportunityEvent(accId);
        Integer countOpportunityLagardere = getOpportunityLagardere(accId);
        Decimal amountOpportunityLagardere = getOpportunityLagardereAmount(accId);
        String lastCreatedOpportunityLagardereFormated = getLastCreatedOpportunityLagardere(accId);
        Integer countOpenactivities = getOpenActivities(accId);

        return new SyntheseData(countContact, countOpportunity, lastCreatedOpportunityFormated, countOpportunityB2B, lastCreatedOpportunityB2BFormated,
        countOpportunityB2BAbo, countOpportunityB2BPlacesSeches, amountOpportunityB2BPlacesSeches, amountOpportunityB2B, amountOpportunity, countOpportunityEvent,
        amountOpportunityEvent, lastCreatedOpportunityEventFormated, countOpportunityLagardere, amountOpportunityLagardere, lastCreatedOpportunityLagardereFormated,
        countOpenactivities);
    }
}

My syntheseComponent.js :

import { LightningElement, api, wire } from 'lwc';
import getSyntheseData from '@salesforce/apex/SyntheseController.getSyntheseData';

export default class SyntheseComponent extends LightningElement {
    @api recordId;
    @wire(getSyntheseData, { accId: '$recordId' }) syntheseData;
}

My syntheseComponent.html :

<template>
  <lightning-card title="Synthèse" icon-name="standard:entitlement">
    <lightning-tabset>
      <lightning-tab label="Général">
        <div class="slds-m-around_medium">
          <article class="slds-tile slds-media">
            <div class="slds-media__body">
              <div class="slds-tile__detail">
                <dl class="slds-list_horizontal slds-wrap">
                  <dt class="slds-item_label slds-text-color_weak slds-truncate" title="Contacts">Nb Contacts:</dt>
                  <dd id="contactsId" class="slds-item_detail slds-truncate contactsId" title="Description for first label"><b>{syntheseData.data.countContact}</b></dd>
                  <dt class="slds-item_label slds-text-color_weak slds-truncate" title="Opportunités">Nb Opportunités:</dt>
                  <dd class="slds-item_detail slds-truncate" title="Description for second label"><b>{syntheseData.data.countOpportunity}</b></dd>
                  <dt class="slds-item_label slds-text-color_weak slds-truncate" title="Montant">Montant Opportunités:</dt>
                  <dd class="slds-item_detail slds-truncate" title="Description for second label"><b>{syntheseData.data.amountOpportunity}€</b></dd>
                  <dt class="slds-item_label slds-text-color_weak slds-truncate" title="Open Activities">Open Activities:</dt>
                  <dd class="slds-item_detail slds-truncate" title="Description for second label"><b>{syntheseData.data.countOpenactivities}</b></dd>
                  <dt class="slds-item_label slds-text-color_weak slds-truncate" title="Date dernière opp">Dernière Opportunité:</dt>
                  <dd class="slds-item_detail slds-truncate" title="Description for second label"><b>{syntheseData.data.lastCreatedOpportunityFormated}</b></dd>
                </dl>
              </div>
            </div>
          </article>
        </div>
      </lightning-tab>
      <lightning-tab label="Opp B2B" title="2nd tab extended title">
        <div class="slds-m-around_medium">
            <article class="slds-tile slds-media">
              <div class="slds-media__body">
                <div class="slds-tile__detail">
                  <dl class="slds-list_horizontal slds-wrap">
                    <dt class="slds-item_label slds-text-color_weak slds-truncate" title="Opp B2B">Nb Opp B2B:</dt>
                    <dd class="slds-item_detail slds-truncate" title="Description for first label"><b>{syntheseData.data.countOpportunityB2B}</b></dd>
                    <dt class="slds-item_label slds-text-color_weak slds-truncate" title="Montant Opp B2B">Montant Opp B2B:</dt>
                    <dd class="slds-item_detail slds-truncate" title="Description for second label"><b>{syntheseData.data.amountOpportunityB2B}€</b></dd>
                    <dt class="slds-item_label slds-text-color_weak slds-truncate" title="Date derniere opp B2B">Dernière Opp B2B:</dt>
                    <dd class="slds-item_detail slds-truncate" title="Description for second label"><b>{syntheseData.data.lastCreatedOpportunityB2BFormated}</b></dd>
                    <dt class="slds-item_label slds-text-color_weak slds-truncate" title="Opp B2B Abo">Nb Opp Abo B2B:</dt>
                    <dd class="slds-item_detail slds-truncate" title="Description for second label"><b>{syntheseData.data.countOpportunityB2BAbo}</b></dd>
                    <dt class="slds-item_label slds-text-color_weak slds-truncate" title="Montant opp abo B2B">Montant Opp Abo B2B:</dt>
                    <dd class="slds-item_detail slds-truncate" title="Description for second label"><b>{syntheseData.data.amountOpportunityB2B}€</b></dd>
                    <dt class="slds-item_label slds-text-color_weak slds-truncate" title="Opp B2B PS">Nb Opp Places Sèches B2B:</dt>
                    <dd class="slds-item_detail slds-truncate" title="Description for second label"><b>{syntheseData.data.countOpportunityB2BPlacesSeches}</b></dd>
                    <dt class="slds-item_label slds-text-color_weak slds-truncate" title="Montant opp PS B2B">Montant Opp Places Sèches B2B:</dt>
                    <dd class="slds-item_detail slds-truncate" title="Description for second label"><b>{syntheseData.data.amountOpportunityB2BPlacesSeches}€</b></dd>
                  </dl>
                </div>
              </div>
            </article>
          </div>
      </lightning-tab>
      <lightning-tab label="Opp Event">
        <div class="slds-m-around_medium">
          <article class="slds-tile slds-media">
            <div class="slds-media__body">
              <div class="slds-tile__detail">
                <dl class="slds-list_horizontal slds-wrap">
                  <dt class="slds-item_label slds-text-color_weak slds-truncate" title="Opp Event">Nb Opp Event:</dt>
                  <dd class="slds-item_detail slds-truncate" title="Description for first label"><b>{syntheseData.data.countOpportunityEvent}</b></dd>
                  <dt class="slds-item_label slds-text-color_weak slds-truncate" title="Montant Opp Event">Montant Opp Event:</dt>
                  <dd class="slds-item_detail slds-truncate" title="Description for second label"><b>{syntheseData.data.amountOpportunityEvent}€</b></dd>
                  <dt class="slds-item_label slds-text-color_weak slds-truncate" title="Date derniere opp Event">Dernière Opp Event:</dt>
                  <dd class="slds-item_detail slds-truncate" title="Description for second label"><b>{syntheseData.data.lastCreatedOpportunityEventFormated}</b></dd>
                </dl>
              </div>
            </div>
          </article>
        </div>
      </lightning-tab>
      <lightning-tab label="Opp Lagardère">
        <div class="slds-m-around_medium">
          <article class="slds-tile slds-media">
            <div class="slds-media__body">
              <div class="slds-tile__detail">
                <dl class="slds-list_horizontal slds-wrap">
                  <dt class="slds-item_label slds-text-color_weak slds-truncate" title="Opp Lagardere">Nb Lagardère:</dt>
                  <dd class="slds-item_detail slds-truncate" title="Description for first label"><b>{syntheseData.data.countOpportunityLagardere}</b></dd>
                  <dt class="slds-item_label slds-text-color_weak slds-truncate" title="Montant Opp Lagardere">Montant Opp Lagardère:</dt>
                  <dd class="slds-item_detail slds-truncate" title="Description for second label"><b>{syntheseData.data.amountOpportunityLagardere}€</b></dd>
                  <dt class="slds-item_label slds-text-color_weak slds-truncate" title="Date derniere opp Event">Dernière Opportunité Lagardère:</dt>
                  <dd class="slds-item_detail slds-truncate" title="Description for second label"><b>{syntheseData.data.lastCreatedOpportunityLagardereFormated}</b></dd>
                </dl>
              </div>
            </div>
          </article>
        </div>
      </lightning-tab>
    </lightning-tabset>
  </lightning-card>
</template>

And the error message error message

If someone can enlighten me about what i'm doing wrong would be awesome.

1 Answer 1

2

The wired property syntheseData is not defined when the component initialises and will be populated by the wire service asynchronously later. Try the following by adding a getter method in your JavaScript:

get countContact() { 
    return this.syntheseData ? this.syntheseData.data.countContact : 0;
}

In your markup bind countContact directly:

<b>{countContact}</b>


To check the received data in JavaScript do the following:

import { LightningElement, api, wire } from 'lwc';
import getSyntheseData from '@salesforce/apex/SyntheseController.getSyntheseData';

export default class SyntheseComponent extends LightningElement {
  @api recordId;
  @track syntheseData;//NOTE: added own property now

  get countContact() { 
    //NOTE: updated the access here:
    return this.syntheseData ? this.syntheseData.countContact : 0;
  }

  @wire(getSyntheseData, { accId: '$recordId' })
  wiredSyntheseData({error, data}) {
    if(error) {
      console.error(error);
    } else if(data) {
      this.syntheseData = data;
    }
  }
}

You should be able to see if any possible errors in the browser console.

5
  • Still having the same error message while using your code. Maybe is it coming from my Controller? Feb 11, 2020 at 12:14
  • I updated my answer - please try my code and see if there are any errors because of the Apex side Feb 11, 2020 at 13:14
  • It's working nice for my get countContact i'm retrieving the data i want. But it's not working for all my other get methods, this is incomprehensible... Feb 11, 2020 at 13:40
  • Nevermind, i've re righted both methods with the way you updated and it's working perfectly. Thanks you very much. Now i got to work on how to make Jest test for unit test, i'm pretty novice about it Feb 11, 2020 at 13:46
  • Glad I could help - if the answer solved your problem please always mark it as the correct one to help others find the most valuable information easier. Feb 11, 2020 at 13:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.