How to write Future method in Apex | How to make an API callout using future annotation?

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 มี.ค. 2021
  • In this video Shrey has explained how to write Future method in apex and process to make API callout using future annotation.
    For Understand the Future Method watch this video:
    • Understanding Future M...
    We hope you enjoy the video and take another step forward in your journey with Salesforce. This video is from the Salesforce Administrator & App Builder course which is designed and curated by Shrey Sharma, one of the top best Salesforce Trainer in the world.
    ------
    Get your free copy of notes here: www.shreysharma.com/salesforc...
    ------
    Grow your business with THE BEST SALESFORCE IMPLEMENTATION and CONSULTANCY SERVICES
    Reach us out here: cyntexa.com​
    ------
    Get the BEST SALESFORCE COURSES & TRAINING here shreysharma.com​
    ----
    STALK ME ON:
    Instagram: / ​
    Facebook: / ​
    Twitter: / iamshreysharma​
    LinkedIn: / imshreysh...​
    ----
    Shrey is a Chief Executive Officer at Cyntexa which is considered as one of the top Salesforce Consulting Partner in USA, UK, UAE, Australia, Singapore & India having a vibrant team of 100+ certified Salesforce experts which include developers, architects, consultants, administrators, and MVPs.
    Shrey took Cyntexa from 5 to 100+ people in less than 1.5 years while multiplying the revenues by 8 times. Shrey has been an entrepreneur since the age of 13 as he was buying and selling stuff and making money in the school itself. Shrey is the Youngest Salesforce MVP in the world who firmly believes in providing value to the people and building long-term value-based relationships. His mission is to disrupt the way professional technical services are delivered by bringing back the empathy for the end-user rather than being operational and transactional.
    Shrey is popularly known as Salesforce Hulk in the Salesforce ecosystem as he was the first one to start creating videos on Salesforce on his TH-cam channel named as Salesforce Hulk and that too at the age of 19. Shrey is also the founder of S2 Labs which is a Salesforce Training Company, being the 1st one to start Salesforce training in Rajasthan, India, and currently selling his courses worldwide. Shrey is also a marvelous speaker who actively presents on topics that revolve around Salesforce and Entrepreneurship in various worldwide conferences. Shrey has also been a Judge in multiple technical and business hackathons organized by the Government of India like Smart India Hackathon.
    Shrey is a leader with out of the box thinking who emphasizes not only on hitting the sales targets but also on providing an amazing experience to the customers as well as employees. Shrey believes in building a team with strong values, ethics, and behavior which leads to the amazing culture at Cyntexa.
    #salesforce​
    #learnsalesforce​
    #salesforce​ hulk
    #futuremethods

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

  • @jhabarmaltakar6358
    @jhabarmaltakar6358 2 ปีที่แล้ว +5

    The reason why sObjects can’t be passed as arguments to future methods is because the sObject might change between the time you
    call the method and the time it executes. In this case, the future method will get the old sObject values and might overwrite them. To
    work with sObjects that already exist in the database, pass the sObject ID instead (or collection of IDs) and use the ID to perform a query
    for the most up-to-date record. The following example shows how to do so with a list of IDs.
    global class FutureMethodRecordProcessing
    {
    @future
    public static void processRecords(List recordIds)
    {
    // Get those records based on the IDs
    List accts = [SELECT Name FROM Account WHERE Id IN :recordIds];
    // Process records
    }
    }

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

    Crystal clear. Thanks for sharing.

  • @mayurtripathi3288
    @mayurtripathi3288 3 ปีที่แล้ว

    Simple and crystal clear

  • @dev.antunes
    @dev.antunes 2 ปีที่แล้ว

    Thanks, Shrey!

  • @radhakrishnasharma9020
    @radhakrishnasharma9020 3 ปีที่แล้ว

    Thanks for sharing knowledge

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

    because the sObject might change between the time you call the method and the time it executes. In this case, the future method will get the old sObject values and might overwrite them

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

    Excellent explanation! Keep up the good work!

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

    Thank you a lot

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

    Thanks for the sharing the concept in a easy way.
    As we know that sobject can't be used as a parameter in future method. This is because, any sobject record might be updated in between the job is queued and start it's execution. Their will be a possibility of sobject record overwriting. Or we might be performing the task using the old records.

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

      Absolutely correct, Subrata! Well done 👍🏻

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

      Hello and thank you for the update. So if I want to use an Apex Trigger when a Case becomes "Closed", what would be your recommandation? Thanks

  • @sushanthsinghvarma4921
    @sushanthsinghvarma4921 3 ปีที่แล้ว

    Great video shrey!!

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

    @Salesforce Hulk - Why I can't call the future method from the batch class, but I can call batch class within a batch class under the finish method as both are asynchronous?

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

    Batch apex is also execute when the resources are available. So lets suppose there are 1000 records we are updating each record in batch apex and it first excute the 200 record. Then lets suppose resources are hold by some another classes and in the meantime records has changed. so when resources are available it continues to execute batch records. So in that case it will change or overwrite the sobject values?

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

    Salesforce Guru

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

    Nice

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

    You can't pass sobjects as parameters to future method because when you execute one future method then there are two main lifecycle points of that method. First is it will be queued and whenever resources will be available then it will be executed (2nd point).
    So when it is queued and when it is actually executed, in between this time that sobjects can be updated or may have been changed there values. So that's why Salesforce doesn't allow to pass sobjects.

  • @nikitayadav2437
    @nikitayadav2437 3 ปีที่แล้ว

    hi..I dont find your videos related to queueable apex..can i plz give me a links to those videos if available?

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

    Is there any issues coming up writing a Future method inside a Queueable Class? nd how to do that , please do a video or please reply with an examplry use-case or scenario. Thanks

  • @RaviKumar0910
    @RaviKumar0910 3 ปีที่แล้ว

    1st comment
    Thanks for sharing your knowledge
    Keep going
    All the Best

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

    @salesforce Hulk, why we cannot call a future method from another future method? I mean what is the exact reason behind this ??

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

    We cannot pass sobject as parameter. As the object value can be updated in between while execution.

  • @sufyanpanamkavil9632
    @sufyanpanamkavil9632 3 ปีที่แล้ว

    iam using the same code but getting {error={code=101, info=You have not supplied an API Access Key. [Required format: access_key=YOUR_ACCESS_KEY], type=missing_access_key}, success=false} what is the issue?

  • @mingwayne2297
    @mingwayne2297 3 ปีที่แล้ว

    How to create an apxc file please?

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

    FATAL_ERROR System.NullPointerException: Attempt to de-reference a null object
    Decimal conversionRate = (Decimal) mMap.get('INR'); //at this line showing above error

  • @user-bd7xv2hk5m
    @user-bd7xv2hk5m 2 ปีที่แล้ว

    How should we test this callout???? Because future method doesnt return anything

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

    Why future method can't call another future method

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

    What is the behaviour behind scenes I mean what happens with governor limits when I use future method
    ?

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

      Hi Mario, By using Future Method in Asynchronous way, Governor limits can be increased ie SOQL increased to 200 and HEap size to 12MB from 6MB.

  • @komalthorat3774
    @komalthorat3774 3 ปีที่แล้ว

    The reason why sObjects can’t be passed as arguments to future methods is because the sObject might change between the time you call the method and the time it executes. In this case, the future method will get the old sObject values and might overwrite them.

    • @SalesforceHulk
      @SalesforceHulk  3 ปีที่แล้ว

      Exactly, Komal. You are absolutely correct 👍🏻