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
chandra2ravichandra2ravi 

Whats wrong in the Code

HI ALL,

I am beginner in sfdc.

 

In the following code i am updating contact records. but following error is coming. i am updating interested_tech__c.

 

Apex trigger CreateContactAccountInsert caused an unexpected exception, contact your administrator: CreateContactAccountInsert: System.LimitException: Too many future calls: 11

 

if(trigger.isupdate)

    {

           String s = 'test'; 

        Set<id> ownerIds = new Set<id>();

        for (Contact a :[Select Id,LastName from Contact where lastname like :(s+'%')])

           ownerIds.add(a.Id);   

 

      Contact[] owners = [Select Id,interested_tech__c from Contact Where Id in :ownerIds for update];  

 

       for (Contact Cnt: owners  ){

       Cnt.interested_tech__c='C';

       system.debug('TestMethod'+ Cnt.interested_tech__c);

       update Cnt;

       }

    }

 

James (CloudAnswers)James (CloudAnswers)

It sounds like you have another trigger on case that is doing a future call, but you may try this.  You have to bulkify your update:

 

 

if(trigger.isupdate)

    {

           String s = 'test'; 

        Set<id> ownerIds = new Set<id>();

        for (Contact a :[Select Id,LastName from Contact where lastname like :(s+'%')])

           ownerIds.add(a.Id);   

 

      Contact[] owners = [Select Id,interested_tech__c from Contact Where Id in :ownerIds for update];  

 

       for (Contact Cnt: owners  ){

       Cnt.interested_tech__c='C';

       system.debug('TestMethod'+ Cnt.interested_tech__c);

       }

       update owners;

    }

marioluisscmarioluissc

Hi,

 

This error does reference for Limit of Future "@future" Callouts or calls to webservices. But in your code I dont saw any callout and any @future call.

This error can to be showing becouse you are trying to call update method more than 10 times within of your loop below:

 

for (Contact Cnt: owners  ){

       Cnt.interested_tech__c='C';

       system.debug('TestMethod'+ Cnt.interested_tech__c);

       update Cnt;

       }

 

you can to try this:

 

for(Integer i=0; i<owners.size();i++){

   owners[i].interested_tech__c='C';

   system.debug('TestMethod'+ owners[i].interested_tech__c);

}

update owners;

 

it's same code, but here the update method is called once.

 

 

chandra2ravichandra2ravi

Same Error is Coming...