Skip to main content

I have a class that calls to an apex method with in a for loop and that method in-turn calls other apex method. All the methods have SOQL's in them.

Running into 101 SOQL issue.

for(sobject obj:somelist ) {  apexclass1.mehtod1(obj); } public class apexclass1 {  public void method1(obj) {  List<Sobject> queryresults = [select id from sobject where id=:obj.Id];  apexclass2.method2(queryresults .Id);  } } public class apexclass2 {  public void method2(Id) {  List<Sobject> queryresults = [select id from sobject where id=:Id];    } } 

I tried to bulkify the methods by eliminating loops and passing list<> instead of single record to methods. But I might end-up disturbing existing functionality somewhere.

What would be the better and safe approach now?

I have a class that calls to an apex method with in a for loop and that method in-turn calls other apex method. All the methods have SOQL's in them.

Running into 101 SOQL issue.

for(sobject obj:somelist ){ apexclass1.mehtod1(obj); } public class apexclass1{ public void method1(obj){ List<Sobject> queryresults = [select id from sobject where id=:obj.Id]; apexclass2.method2(queryresults .Id); } } public class apexclass2{ public void method2(Id){ List<Sobject> queryresults = [select id from sobject where id=:Id];   } } 

I tried to bulkify the methods by eliminating loops and passing list<> instead of single record to methods. But I might end-up disturbing existing functionality somewhere.

What would be the better and safe approach now?

I have a class that calls to an apex method with in a for loop and that method in-turn calls other apex method. All the methods have SOQL's in them.

Running into 101 SOQL issue.

for(sobject obj:somelist) {  apexclass1.mehtod1(obj); } public class apexclass1 {  public void method1(obj) {  List<Sobject> queryresults = [select id from sobject where id=:obj.Id];  apexclass2.method2(queryresults.Id);  } } public class apexclass2 {  public void method2(Id) {  List<Sobject> queryresults = [select id from sobject where id=:Id];  } } 

I tried to bulkify the methods by eliminating loops and passing list<> instead of single record to methods. But I might end-up disturbing existing functionality somewhere.

What would be the better and safe approach now?

deleted 133 characters in body; edited tags
Source Link
Adrian Larson
  • 152.6k
  • 38
  • 250
  • 434

I have a question on the best practices we have to implement.

I have a scenario,

I have a class that calls to an apex method with in a for loop and that method in-turn calls other apex method. All the methods have SOQL's in them.

Running into 101 SOQL issue.

for(sobject obj:somelist ){ apexclass1.mehtod1(obj); } public class apexclass1{ public void method1(obj){ List<Sobject> queryresults = [select id from sobject where id=:obj.Id]; apexclass2.method2(queryresults .Id); } } public class apexclass2{ public void method2(Id){ List<Sobject> queryresults = [select id from sobject where id=:Id]; } } 

I tried to bulkify the methods by eliminating loops and passing list<> instead of single record to methods. But I might end-up disturbing existing functionality somewhere.

What would be the better and safe approach now?

I need your inputs please!!

Thank you.

I have a question on the best practices we have to implement.

I have a scenario,

I have a class that calls to an apex method with in a for loop and that method in-turn calls other apex method. All the methods have SOQL's in them.

Running into 101 SOQL issue.

for(sobject obj:somelist ){ apexclass1.mehtod1(obj); } public class apexclass1{ public void method1(obj){ List<Sobject> queryresults = [select id from sobject where id=:obj.Id]; apexclass2.method2(queryresults .Id); } } public class apexclass2{ public void method2(Id){ List<Sobject> queryresults = [select id from sobject where id=:Id]; } } 

I tried to bulkify the methods by eliminating loops and passing list<> instead of single record to methods. But I might end-up disturbing existing functionality somewhere.

What would be the better and safe approach now?

I need your inputs please!!

Thank you.

I have a class that calls to an apex method with in a for loop and that method in-turn calls other apex method. All the methods have SOQL's in them.

Running into 101 SOQL issue.

for(sobject obj:somelist ){ apexclass1.mehtod1(obj); } public class apexclass1{ public void method1(obj){ List<Sobject> queryresults = [select id from sobject where id=:obj.Id]; apexclass2.method2(queryresults .Id); } } public class apexclass2{ public void method2(Id){ List<Sobject> queryresults = [select id from sobject where id=:Id]; } } 

I tried to bulkify the methods by eliminating loops and passing list<> instead of single record to methods. But I might end-up disturbing existing functionality somewhere.

What would be the better and safe approach now?

Source Link
Anurag
  • 2.3k
  • 7
  • 43
  • 69

bestpractice for calling apex methods

I have a question on the best practices we have to implement.

I have a scenario,

I have a class that calls to an apex method with in a for loop and that method in-turn calls other apex method. All the methods have SOQL's in them.

Running into 101 SOQL issue.

for(sobject obj:somelist ){ apexclass1.mehtod1(obj); } public class apexclass1{ public void method1(obj){ List<Sobject> queryresults = [select id from sobject where id=:obj.Id]; apexclass2.method2(queryresults .Id); } } public class apexclass2{ public void method2(Id){ List<Sobject> queryresults = [select id from sobject where id=:Id]; } } 

I tried to bulkify the methods by eliminating loops and passing list<> instead of single record to methods. But I might end-up disturbing existing functionality somewhere.

What would be the better and safe approach now?

I need your inputs please!!

Thank you.