SALESFORCE – Créer un composant liste avec des données externes – partie 1

Dans ce guide je vais créer un composant Lightning avec un affichage sous forme de liste de détail lié à un contact. Les données alimentant la liste sont issues d’un service externe via une API REST.

Création du composant Lightning

La plupart des opérations vont se dérouler dans la Developer Console. Pour l’ouvrir il faut cliquer sur l’engrenage en haut à droite. Pour avoir accès à toute les possibilités du développement (accès webservice) il est indispensable d’effectuer le développement et les test dans une organisation sandbox. Salesforce n’autorise pas de développer directement sur l’organisation de production.

Petite aparté, pour pouvoir passer son code de la sandbox à la production, il faut impérativement disposer d’une couverture de code suffisante pour les classes APEX qui seront développées.

Dans la Developer Console, choisr le menu File->New-> Lightning Component :

Il faut saisir les informations souhaitées pour le nom du composant et les options souhaitées pour l’intégration du composant dans les éléments lightning. Une fois la création lancé, la Developer Console va changer l’affichage et proposer la liste des éléments indispensables et optionnels.

Création du Composant

Le premier élément, la partie component contiendra la présentation du composant sous un format HTML. Dans mon exemple il s’agit d’afficher la liste des mails envoyés depuis sendinblue. Je me suis basé sur l’aide de salesforce présentant le composant Datatable : https://developer.salesforce.com/docs/component-library/bundle/lightning:datatable/example

Voici l’exemple de mon code :

Il faut noter dans la définition du composant aura, la partie controller. Cet élément défini pour la partie client le controller qui sera appelé en backend. Je vais donc avoir une classe SendinblueDataTableController qui retournerra une Liste de SendinblueAPIEvent (objet à définir également). Et recordIdContact contiendra l’ID du contact salesforce qui sera le paramètre passé à mon controller.

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" 
                access="global" 
                controller="SendinblueDataTableController" >
	<aura:attribute name="data" type="SendinblueAPIEvent[]"/>
    <aura:attribute name="columns" type="List"/>
    <aura:attribute name="recordIdContact" type="String" default="{!v.recordId}"/>
   

    <!-- handlers-->
    <aura:handler name="init" value="{! this }" action="{! c.init }"/>


    <!-- the container element determine the height of the datatable -->
    <div style="height: 300 px">
        <lightning:datatable
                keyField="id"
                data="{! v.data }"
                columns="{! v.columns }"
                hideCheckboxColumn="true"/>
    </div>
</aura:component>

Ajout du Controller

Le controller contient le code logique qui sera exécuté côté client pour alimenter les données de la liste. Dans mon cas il s’agit uniquement de faire un appel à une API lors du chargement du composant. Le code ici est en javascript, il est possible comme je l’ai fait de mettre des éléments de débogage en utilisant le console.log qui affichera les messages dans la fenêtre console du navigateur.

({
	init : function(component, event, helper) {        
		  component.set('v.columns', [
            {label: 'Sujet', fieldName: 'subject', type: 'text'},
            {label: 'Date envoi', fieldName: 'date_Z', type: 'date'},
            {label: 'Email', fieldName: 'email', type: 'text'}
        ]);

        console.log("APPEL getEmailFromlAccount");
		var action = component.get("c.getEmailFromAccount");
        action.setParams({
        	contactId: component.get('v.recordIdContact')
    	});
        action.setCallback(this, function(response) {

        	var state = response.getState();
        	var data = response.getReturnValue();
        	if(response.getState() == "SUCCESS"){
            	component.set('v.data', data);                
        	} 
    	});
         $A.enqueueAction(action);        
	}
})

Dans les autres éléments constitutifs d’un composant, on peut créer un helper. Il permet de mettre à disposition des fonctions de formatage, ou de comportement sur les données du composants (tri par exemple.) Dans mon cas je n’en n’ai pas eu besoin.

Des élements de style, d’image et de documentation peuvent être ajouté.

Création de la classe controller APEX

A partir de là, le développement est orienté sur la partie serveur (backend). Le langage utilisé par Salesforce est APEX, qui est très proche du Java. Dans la Developer Console, choisir File -> New -> Apex Class.

public class SendinblueDataTableController {
	@AuraEnabled
    public static List<SendinblueAPIEvent> getEmailFromAccount(String contactId){
        String email = '';
        List<Contact> contacts = [select email from Contact where Id = :contactId];
        if (contacts != null){
			for(Contact c : contacts){
   				email = c.email;
			}
        } else {
            email = 'test@scandevelopers.com';
        }
        
        List<SendinblueAPIEvent> sobj = new List<SendinblueAPIEvent>();
        string strListEvent = SendinblueAPI.getListEmail(email);
        SendinblueApexJson obj = SendinblueApexJson.parse(strListEvent);
        if ((obj != null) && (obj.events != null)){
            Integer i=0;
            for (SendinblueApexJson.Events item : obj.events){
                if (i< 5){
                SendinblueAPIEvent apiEvent = new SendinblueAPIEvent();
                apiEvent.email = item.email;
                apiEvent.date_Z = item.date_Z;
                apiEvent.subject = item.subject;
                sobj.add(apiEvent);
                }
                i++;
            }
        }
        return sobj;
    }
  }

La méthode qui sera accessible depuis le composant lightning doit être préfixé avec l’annotation @AuraEnabled. Dans l’exemple suivant, je vais chercher dans un premier temps à récupérer l’email du contact à partir de son ID passé en paramètre. Ensuite j’accède à l’API Sendinblue que j’ai encapsulé, et je ne récupère que les 5 premiers enregistrements.

39 Comments

  1. Baixar WhatsApp para Iphone

    28 juillet 2026 - 17 h 05 min
    Reply

    I?ve read a few excellent stuff here. Definitely worth bookmarking for revisiting. I wonder how so much effort you put to make any such magnificent informative site.

  2. Hollow butt plugs

    29 juillet 2026 - 10 h 24 min
    Reply

    Hiya, I am really glad I have found this info. Nowadays bloggers publish only about gossips and internet and this is actually frustrating. A good blog with exciting content, this is what I need. Thank you for keeping this web site, I’ll be visiting it. Do you do newsletters? Can not find it.

  3. viva88link

    9 août 2026 - 17 h 52 min
    Reply

    I?ve read a few good stuff here. Definitely price bookmarking for revisiting. I wonder how much effort you set to create this kind of great informative website.

  4. viva88

    10 août 2026 - 4 h 13 min
    Reply

    Excellent web site. A lot of useful info here. I?m sending it to several pals ans additionally sharing in delicious. And obviously, thank you to your effort!

  5. daman games app

    13 août 2026 - 19 h 19 min
    Reply

    Good write-up, I am normal visitor of one?s site, maintain up the nice operate, and It is going to be a regular visitor for a long time.

  6. daman games app

    14 août 2026 - 0 h 40 min
    Reply

    What?s Happening i am new to this, I stumbled upon this I’ve found It absolutely useful and it has helped me out loads. I hope to contribute & help other users like its aided me. Great job.

  7. daman

    14 août 2026 - 12 h 01 min
    Reply

    Hey there! Do you use Twitter? I’d like to follow you if that would be ok. I’m definitely enjoying your blog and look forward to new posts.

  8. daman games app

    15 août 2026 - 14 h 18 min
    Reply

    Thanks for this wonderful article. One other thing is that nearly all digital cameras can come equipped with a new zoom lens that allows more or less of any scene for being included by means of ‘zooming’ in and out. All these changes in {focus|focusing|concentration|target|the a**** length will be reflected inside the viewfinder and on big display screen on the back of the actual camera.

  9. daman games app

    15 août 2026 - 18 h 02 min
    Reply

    Thanks for your posting. One other thing is individual American states have their own laws in which affect property owners, which makes it very difficult for the our lawmakers to come up with the latest set of recommendations concerning property foreclosure on home owners. The problem is that a state provides own regulations which may have impact in an undesirable manner in regards to foreclosure plans.

  10. daman game

    15 août 2026 - 22 h 12 min
    Reply

    I used to be very pleased to seek out this net-site.I wished to thanks to your time for this excellent read!! I undoubtedly enjoying every little little bit of it and I’ve you bookmarked to take a look at new stuff you weblog post.

  11. klive

    1 septembre 2026 - 11 h 16 min
    Reply

    It?s onerous to seek out knowledgeable folks on this topic, but you sound like you know what you?re talking about! Thanks

  12. SEO Strategy Room

    2 septembre 2026 - 9 h 01 min
    Reply

    Heya are using WordPress for your site platform? I’m new to the blog world but I’m trying to get started and set up my own. Do you require any html coding knowledge to make your own blog? Any help would be greatly appreciated!

  13. Haha

    2 septembre 2026 - 18 h 22 min
    Reply

    Many thanks for this article. I’d personally also like to say that it can possibly be hard if you are in school and merely starting out to initiate a long credit score. There are many students who are simply trying to pull through and have a long or favourable credit history is often a difficult element to have.

  14. เว็บหวย

    2 septembre 2026 - 19 h 03 min
    Reply

    I like the valuable info you supply in your articles. I will bookmark your weblog and take a look at again here regularly. I am quite certain I will be told many new stuff proper here! Good luck for the following!

  15. Haha

    2 septembre 2026 - 19 h 40 min
    Reply

    That is the suitable weblog for anybody who needs to search out out about this topic. You notice a lot its almost onerous to argue with you (not that I truly would need?HaHa). You definitely put a new spin on a topic thats been written about for years. Great stuff, just great!

  16. หี

    3 septembre 2026 - 9 h 32 min
    Reply

    We are a gaggle of volunteers and opening a brand new scheme in our community. Your web site provided us with valuable information to work on. You’ve done an impressive activity and our whole group will be grateful to you.

  17. Haha

    3 septembre 2026 - 13 h 13 min
    Reply

    You should take part in a contest for among the finest blogs on the web. I will recommend this website!

  18. สล็อต

    3 septembre 2026 - 13 h 20 min
    Reply

    I?m not positive where you’re getting your info, but good topic. I must spend a while learning much more or understanding more. Thanks for fantastic information I used to be in search of this information for my mission.

  19. Haha

    3 septembre 2026 - 14 h 12 min
    Reply

    My brother recommended I may like this blog. He was once entirely right. This put up truly made my day. You cann’t consider just how much time I had spent for this information! Thanks!

  20. หี

    3 septembre 2026 - 15 h 25 min
    Reply

    Heya i?m for the first time here. I came across this board and I find It really useful & it helped me out much. I hope to give something back and aid others like you aided me.

  21. สล็อต

    3 septembre 2026 - 17 h 58 min
    Reply

    Hello! I could have sworn I’ve been to this blog before but after checking through some of the post I realized it’s new to me. Anyhow, I’m definitely delighted I found it and I’ll be book-marking and checking back frequently!

  22. easyapplai

    4 septembre 2026 - 16 h 19 min
    Reply

    I have observed that in the world the present moment, video games include the latest popularity with kids of all ages. Occasionally it may be extremely hard to drag the kids away from the games. If you want the very best of both worlds, there are plenty of educational activities for kids. Thanks for your post.

  23. www.easyapplai.com

    4 septembre 2026 - 16 h 58 min
    Reply

    Magnificent beat ! I wish to apprentice while you amend your web site, how could i subscribe for a blog web site? The account aided me a acceptable deal. I had been a little bit acquainted of this your broadcast offered bright clear concept

  24. Easy Appl AI

    4 septembre 2026 - 17 h 33 min
    Reply

    I do enjoy the way you have presented this specific difficulty plus it does indeed present me personally a lot of fodder for thought. On the other hand, through just what I have experienced, I basically trust when the actual feedback pack on that people stay on issue and not embark upon a soap box of some other news of the day. Still, thank you for this outstanding point and while I do not really agree with it in totality, I regard your standpoint.

  25. Roof Installation

    6 septembre 2026 - 3 h 45 min
    Reply

    Hey would you mind letting me know which hosting company you’re working with? I’ve loaded your blog in 3 completely different browsers and I must say this blog loads a lot faster then most. Can you suggest a good hosting provider at a honest price? Many thanks, I appreciate it!

  26. Baixar WhatsApp para Iphone

    6 septembre 2026 - 3 h 47 min
    Reply

    I have taken note that of all sorts of insurance, medical care insurance is the most dubious because of the issue between the insurance policies company’s duty to remain profitable and the client’s need to have insurance. Insurance companies’ earnings on well being plans have become low, consequently some organizations struggle to make a profit. Thanks for the suggestions you reveal through this web site.

  27. Roof Installation

    6 septembre 2026 - 4 h 25 min
    Reply

    I beloved up to you will obtain performed proper here. The sketch is tasteful, your authored subject matter stylish. nonetheless, you command get bought an nervousness over that you want be delivering the following. ill unquestionably come more until now again as precisely the same just about very often inside case you defend this increase.

  28. Baixar WhatsApp para Android

    6 septembre 2026 - 4 h 30 min
    Reply

    Thanks for your helpful post. Through the years, I have come to understand that the actual symptoms of mesothelioma cancer are caused by the actual build up connected fluid relating to the lining of your lung and the upper body cavity. The illness may start while in the chest spot and pass on to other areas of the body. Other symptoms of pleural mesothelioma cancer include fat loss, severe breathing trouble, throwing up, difficulty swallowing, and swelling of the face and neck areas. It needs to be noted that some people having the disease usually do not experience any kind of serious signs or symptoms at all.

  29. Siding Installation

    6 septembre 2026 - 5 h 04 min
    Reply

    Thanks for your article. One other thing is that often individual American states have their very own laws in which affect home owners, which makes it very hard for the the legislature to come up with a brand new set of recommendations concerning home foreclosure on householders. The problem is that every state possesses own legislation which may have interaction in a damaging manner on the subject of foreclosure policies.

  30. Baixar WhatsApp para Android

    6 septembre 2026 - 5 h 11 min
    Reply

    I was just seeking this info for a while. After 6 hours of continuous Googleing, finally I got it in your web site. I wonder what is the lack of Google strategy that do not rank this kind of informative websites in top of the list. Normally the top web sites are full of garbage.

  31. Baixar WhatsApp para Android

    6 septembre 2026 - 14 h 05 min
    Reply

    Usually I don’t read post on blogs, but I wish to say that this write-up very forced me to try and do it! Your writing style has been surprised me. Thanks, very nice post.

  32. Baixar WhatsApp para Android

    6 septembre 2026 - 14 h 32 min
    Reply

    It’s my belief that mesothelioma will be the most fatal cancer. It has unusual attributes. The more I look at it the greater I am confident it does not work like a real solid flesh cancer. If mesothelioma is a rogue viral infection, hence there is the possibility of developing a vaccine and offering vaccination for asbestos exposed people who are vulnerable to high risk connected with developing potential asbestos related malignancies. Thanks for giving your ideas for this important health issue.

  33. Baixar WhatsApp para Iphone

    6 septembre 2026 - 14 h 56 min
    Reply

    Thank you for the sensible critique. Me and my neighbor were just preparing to do a little research on this. We got a grab a book from our area library but I think I learned more clear from this post. I am very glad to see such wonderful information being shared freely out there.

  34. Baixar WhatsApp para Iphone

    6 septembre 2026 - 20 h 22 min
    Reply

    This web site is really a walk-by way of for the entire data you wanted about this and didn?t know who to ask. Glimpse here, and also you?ll undoubtedly uncover it.

  35. Baixar WhatsApp para Iphone

    6 septembre 2026 - 20 h 56 min
    Reply

    Please let me know if you’re looking for a author for your site. You have some really great posts and I believe I would be a good asset. If you ever want to take some of the load off, I’d really like to write some articles for your blog in exchange for a link back to mine. Please send me an email if interested. Cheers!

  36. Baixar WhatsApp para Iphone

    6 septembre 2026 - 21 h 28 min
    Reply

    I like the valuable information you provide in your articles. I?ll bookmark your blog and check again here regularly. I am quite certain I?ll learn many new stuff right here! Good luck for the next!

  37. CTO Migrations

    7 septembre 2026 - 9 h 02 min
    Reply

    Have you ever thought about creating an ebook or guest authoring on other blogs? I have a blog centered on the same information you discuss and would really like to have you share some stories/information. I know my viewers would appreciate your work. If you are even remotely interested, feel free to shoot me an email.

  38. CTO Migration

    7 septembre 2026 - 9 h 33 min
    Reply

    I’m not sure why but this site is loading very slow for me. Is anyone else having this problem or is it a issue on my end? I’ll check back later and see if the problem still exists.

  39. kibris pavyon

    8 septembre 2026 - 12 h 27 min
    Reply

    Heya i am for the primary time here. I came across this board and I find It really helpful & it helped me out a lot. I am hoping to offer one thing back and aid others like you aided me.

Leave a Reply

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Ce site utilise Akismet pour réduire les indésirables. En savoir plus sur la façon dont les données de vos commentaires sont traitées.