• Sushmitha B 15
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies

I have a schedulable batch class which is stateful. In execute am inserting upto 1000 records.

In final method  i have a list of ids of inserted record

global void finish(Database.BatchableContext BC)
  {
                    if(Ids.size()>0)
                    {
                      for(string id : Ids)
                      {
                        // calling a static method sending id as paramter.
                      }
                    }
 
  }


In for loop for every id calling an static method with id as parameter.

The call static method will created an instance of another class which has nearly 10 queries and an http request.

am getting Too many SOQL queries: 201 

This is my static method

global  class SClass
{
  
  public static void SMethod(String id)
  {      
                         
       
         Sclass2 s = new sclass2 (Id,false);
         s.test();// this method has http request
   }           
        
}
 

why do i get this even when we have created new instance for every id. 

Any solution please.

Thanks,

 

Hi,

We have a trigger which calls an static method specified with @future(callout = true) on every insert.

When creating records(insert) from  Schedulable batchclass  the following error occurs

First error: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, triggername: execution of AfterInsert

caused by: System.AsyncException: Future method cannot be called from a future or batch method:

Any solution for this please.

please find my batchclass sample here

 
global class SchedulableBatchClass implements Database.Batchable<sObject>, Schedulable,Database.AllowsCallouts
{
  global Database.QueryLocator start(Database.BatchableContext BC)
  {
    return Database.getQueryLocator( // query here);
  }
  
  global void execute(Database.BatchableContext BC, List<Contact> contacts)
  {
    for(Contact newcontact : contacts)
    {
       
                   
          INSERT newobject; // more than 1000 inserts
       
    }       
  }

  
  global void finish(Database.BatchableContext BC)
  {

  }
  
  global void execute(SchedulableContext SC)
  {
      SchedulableBatchClassFor sbc = new SchedulableBatchClassFor();
      Database.executeBatch(sbc, 600);
  }
}

//trigger
trigger tTrigger on t__c (after insert) 
{
    If(Trigger.isafter && Trigger.isInsert)
    {
      for(Integer i=0; i<trigger.new.Size();i++)
      {
        SomeClass.Staticmethod(trigger.new[i])  ;
      }
    }
}

public class someclass{
@future(callout= true)
    public static void ExecuteSend()
   {
//http request here.
}
}

Thanks.

I am trying to add android device token(Firbase)in the recipient ids of custom notification flow but its showing as an invalid parameter. But its working when I tried using a Test Push notification in salesforce using the same device token

I have used my own app instead of salesforce app. I have followed this documentation https://blog.bessereau.eu/assets/pdfs/salesforce_mobile_push_notifications_implementation.pdf.
My Firebase device token looks like this - dMDqotkLqXA:AaaaabGGdDv9ZpJGRjisqnCz2AyG9AahfGfJJXfuXKqKgYj6RRI8owNNIPR04x6NT7bB4NsRVGgL00Ii-ai0Nbfh7IbnkD5oGS8UoHv6gectuEL-M8digrQQHU0ETpKoFbpb4abmE0

Hi,

We have a trigger which calls an static method specified with @future(callout = true) on every insert.

When creating records(insert) from  Schedulable batchclass  the following error occurs

First error: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, triggername: execution of AfterInsert

caused by: System.AsyncException: Future method cannot be called from a future or batch method:

Any solution for this please.

please find my batchclass sample here

 
global class SchedulableBatchClass implements Database.Batchable<sObject>, Schedulable,Database.AllowsCallouts
{
  global Database.QueryLocator start(Database.BatchableContext BC)
  {
    return Database.getQueryLocator( // query here);
  }
  
  global void execute(Database.BatchableContext BC, List<Contact> contacts)
  {
    for(Contact newcontact : contacts)
    {
       
                   
          INSERT newobject; // more than 1000 inserts
       
    }       
  }

  
  global void finish(Database.BatchableContext BC)
  {

  }
  
  global void execute(SchedulableContext SC)
  {
      SchedulableBatchClassFor sbc = new SchedulableBatchClassFor();
      Database.executeBatch(sbc, 600);
  }
}

//trigger
trigger tTrigger on t__c (after insert) 
{
    If(Trigger.isafter && Trigger.isInsert)
    {
      for(Integer i=0; i<trigger.new.Size();i++)
      {
        SomeClass.Staticmethod(trigger.new[i])  ;
      }
    }
}

public class someclass{
@future(callout= true)
    public static void ExecuteSend()
   {
//http request here.
}
}

Thanks.