Salesforce Developer Tutorial: How to use Wrapper Classes in Apex to Simplify your Integrations

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ส.ค. 2024
  • In this episode we go over how to use wrapper classes to simplify your REST integrations when you receive JSON responses. Instead of manually parsing everything, you can use wrappers to simply your life a TON! Hopefully this helps speed up the dev time on your next integration a bunch.
    Please consider donating to help continue to improve the content produced for Coding With The Force: www.paypal.com/donate?busines...
    Get Coding With The Force Merch Here: my-store-d20559.creator-sprin...
    GitHub Repo:
    github.com/Coding-With-The-Fo...
    JSON Class Documentation: developer.salesforce.com/docs...
    Get Postman Here: www.postman.com/
    JSON2Apex Heroku App: json2apex.herokuapp.com/
    Follow all of our social media here:
    Patreon: / codingwiththeforce
    Github: github.com/Coding-With-The-Force
    Facebook: / codingwiththeforce
    Twitter: / coding_force
    Instagram: / codingwiththeforce
    Salesforce development books I recommend:
    Advanced Apex Programming: amzn.to/3lXi8to
    Salesforce Lightning Platform Enterprise Architecture: amzn.to/2R0D4BQ
    Mastering Salesforce DevOps: amzn.to/3lTtTRN
    Apex Design Patterns Book: amzn.to/3DwqljP
    Good Non-SF Specific Development Books:
    Clean Code: amzn.to/35PuMDU
    Clean Architecture: amzn.to/35FYo6A
    Design Patterns: Elements of Reusable Object-Oriented Software Book: amzn.to/3LhvHBd
    -------------------------------------------------------------------------------------------------------------------------
    Table of Contents:
    0:00 - Intro
    0:20 - Go vote on next weeks video topic!
    0:55 - Why are wrapper classes so important?
    2:32 - Reddit JSON Example
    4:30 - The importance of using Postman
    6:32 - Using the JSON2Apex Heroku App
    7:58 - Trimming the wrapper class to only reference what you need
    18:10 - Making the class visible to Lightning Components
    19:26 - Building the integration with Reddit
    43:09 - Outro
    DISCLAIMER: The views and ideas expressed on this TH-cam channel and blog are based on past development experiences and may not always work for your particular scenarios. The advice in these videos may also become outdated as technology advances. They should be used as examples for educational purposes only. Using any shown solutions in your own org is not advisable since they are example scenarios.
    #salesforce #salesforcedeveloper #salesforceadmin

ความคิดเห็น • 27

  • @paxhaven5
    @paxhaven5 3 ปีที่แล้ว +1

    Good information, Matt! Much appreciated.

  • @danieljeffrey3269
    @danieljeffrey3269 3 ปีที่แล้ว +3

    Great video! Well organized and informative! You have a talent for teaching.

  • @jean-francoiscarrier9319
    @jean-francoiscarrier9319 2 ปีที่แล้ว

    Perfect video again! I will have to watch the others too! Thanks!!

  • @kimberlyholland9280
    @kimberlyholland9280 3 ปีที่แล้ว +1

    Yes, I agree with Daniel Jeffrey, you have a talent for teaching. THANK YOU!! & don't change! In past life, I was an OO ABAP developer (yes it is object-oriented..yeah..i know). You are the equivalent of Thomas Jung @SAP! I hope SF scoops you up, if they haven't already!

  • @rahulsethi8914
    @rahulsethi8914 2 ปีที่แล้ว

    Wow man! You really helped me alot!

  • @slackularo
    @slackularo 3 ปีที่แล้ว +1

    Nice work, Matt. This is a great explanation of wrapper class use and an introduction to json2apex.

  • @ignaciomartin3640
    @ignaciomartin3640 3 ปีที่แล้ว +3

    really good information , i learned this doing my official first integration some days ago , so i can tell this is really helpful.

    • @CodingWithTheForce
      @CodingWithTheForce  3 ปีที่แล้ว +1

      Thanks man! I’m glad you liked it and I appreciate the feedback!

  • @parvezalam204
    @parvezalam204 ปีที่แล้ว

    Thank you for it

  • @GreeveCapricous
    @GreeveCapricous 2 ปีที่แล้ว

    Nice Class. Makes me feel a little less timid about approaching the integrations via Apex vs middleware

  • @ManiMahal-pn4ip
    @ManiMahal-pn4ip ปีที่แล้ว

    Thanks Matt for this informative Tutorial. I would like to know if you have made any videos for inbound integrations into salesforce? Thank you.

  • @MrBenjo000
    @MrBenjo000 ปีที่แล้ว

    My json2apex output file looks different with the JSONParser method included in all methods, and each value includes the {get;set;}, some values include _Z, like "public Integer limit_Z {get;set;} // in json: limit" . This makes sense for my use case as I have system values in the json payload and would need a way to parse through this using JSONParser method. I'm wondering how do I initiate this JSONParser method when generating my wrapper class @CodingWithTheForce? Or if you were to include this in your example above how would you initiate that. I've included a sample of the wrapper class. Thanks very much, your videos have been super useful to develop my understanding of rest integration.
    public class JSON2Apex {
    public class Data {
    public String client_ref {get;set;}
    public Integer limit_Z {get;set;} // in json: limit
    public Data(JSONParser parser) {
    while (parser.nextToken() != System.JSONToken.END_OBJECT) {
    if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
    String text = parser.getText();
    if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
    if (text == 'client_ref') {
    client_ref = parser.getText();
    } else if (text == 'limit') {
    limit_Z = parser.getIntegerValue();
    } else {
    System.debug(LoggingLevel.WARN, 'Data consuming unrecognized property: '+text);
    consumeObject(parser);
    }
    }
    }
    }
    }
    }

  • @PuerinTheHunter
    @PuerinTheHunter 3 ปีที่แล้ว +1

    Nice video! Thanks for posting it!
    @36:30 you said string parsing is enormous overhead.
    What if I just use String fieldValue = response.getBody().substringBetween( '"fieldName":"', '',' ); to get a single field??
    Asssume I just need few fields from the JSON response, that would be a lot faster than using wrapper class and deserializing JSON, wouldn't it?

    • @CodingWithTheForce
      @CodingWithTheForce  3 ปีที่แล้ว +2

      If it's a simple JSON object and you're only getting one or two fields from it, that's ok to do. Much more than that though and you'll start to see the performance degradation start to add up.

  • @TK-vt3ep
    @TK-vt3ep ปีที่แล้ว

    How to parse html with img from json you have and insert into salesforce object??? Could you please suggest.

  • @walkswithcedarandmaddy6672
    @walkswithcedarandmaddy6672 2 ปีที่แล้ว +1

    could you possibly do a video explaining these wrapper classes in more detail? I'm having trouble figuring out how to access data that's nested in the wrapper class. it's silly but I'm practicing callouts by making a salesforce pokedex and getting the info from callouts to the pokeapi. I was able to get all the names of the pokemon by using this video. but when I go to the pokemon's individual page there are nested json objects and arrays.
    I think it would be really helpful if you did a couple of different callouts with nested and varied data. I'm fairly new to apex. parsing json is so much easier in javascript and python, lol.

  • @mailme7514
    @mailme7514 2 ปีที่แล้ว

    Hello could you please do few more sessions on same wrapper class integration topic which is also known as Data transfer object it would be very much helpful.

  • @shaswat6297
    @shaswat6297 2 ปีที่แล้ว

    3:30 point of this vdo
    4:30 postman or use han
    6:55 json etto apex class Han direct

  • @pavandkbose
    @pavandkbose 2 ปีที่แล้ว

    Hi ,could you please make a detailed video on Test Class on every aspect??

    • @CodingWithTheForce
      @CodingWithTheForce  2 ปีที่แล้ว

      Hey Pavan, yes! It will be a little while but as part of the Intro to Apex tutorial series I'm currently creating I will be creating some videos going over absolutely everything related to test classes! You can follow the playlist here: th-cam.com/play/PL0wESsiWMBTrCT3kNGIT3HpWLG6SmVr2F.html

    • @pavandkbose
      @pavandkbose 2 ปีที่แล้ว

      @@CodingWithTheForce Sure thanks a lot as I'm from Non- coding background ,I'm finding it difficult to analyse the problem and impliment the right solution..and your videos help me a lot in figuring out the issues..
      Hope one day I also become a software developer as you are🙂

  • @romanregmi1332
    @romanregmi1332 ปีที่แล้ว

    You should have picked a more difficult JSON data.