function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Diwakar G 7Diwakar G 7 

Post Request in Trigger in Batch Update


I have one button which will do batch update and a trigger is written on the same object which checks the present and previous field value. If it is different then I need to make post api call.
Below are codes:

Apex Trigger:
trigger StatusChange on User_Story__c (after update) {
    List<User_Story__c> ulist =;
    for(User_Story__c u: ulist){

    User_Story__c updacc=[select id,name,userStory_reason__c from User_Story__c where id =];

    if(Trigger.oldmap.get( != Trigger.newmap.get({




Apex Class:
global class postrequest{

    public static void apicall(){
            HttpRequest req = new HttpRequest();
        	String endpoint = '';
        	String jsonData = 'ABC';
                req.setHeader('Accept', 'application/json');
      		Http http = new Http();

But, I am getting the below error. Please help me.
caused by: System.AsyncException: Future method cannot be called from a future or batch method:
Khan AnasKhan Anas (Salesforce Developers) 
Hi Diwakar,

Greetings to you!

Salesforce doesn't allow a future method to be called from another future method or a batch job. Before calling your future method, you should check if a future or batch job is already running. This would be a best practice for any code you ever write that calls a future method.
if(System.IsBatch() == false && System.isFuture() == false){ 
    // make your future call here 

Update the trigger logic to leverage the System.isFuture() and System.isBatch() calls so that the future method invocation is not made if the current execution context is future or batch. Record created through such cases should be handled separately using a scheduled batch job or something similar.

Or replace the future method with Queueable Apex.

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Diwakar G 7Diwakar G 7
Hi Khan,

In service function, I am not updating anything releated to User_Story__c object. No logic is written. Just it will written 'Hello from Flask!' response.

Thanks and Regards,
Diwakar G