• Amit "CLS" Rangari
  • NEWBIE
  • 5 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
Hi,

I would like to understand the way 'states' are retained across batches while using Database.Stateful.

Example, If I am using 'totalSum'  as variable to be maintained across batches, then I could do one of the following.  Which one of below is more optimal? does the SF makes sure that the 'serialization of execution' is done only when the Line 2 in option 2 used about to be executed?, 
if the serialization is across all the body of execution(), then option-1 and option-2 does not look too different.
 
//Option 1

execute (scope) {
   foreach(myObject__c obj: scope) {
       totalSum += obj.field_to_sum__c; //<== Line 1
   }
}
 
//Option 2

execute (scope) {
   Integer localSum = 0;
   foreach(myObject__c obj: scope) {
       localSum += obj.field_to_sum__c;
   }

 totalSum += localSum;  //<== Line 2
}

 
Hi,

I have developed a simple class which refers to the global class defined by the underlying package.  I use the ANT with SF migration tools to deploy the code on my dev-org. I get following compilation error:


classes/WSMyAPI_v1.cls -- Error: Dependent class is invalid and needs recompilation:
(namespace)
namespace.class2 : line 141, column 47: Loop variable must be an SObject or list of object3__c (line 166, column 70)

Please note that this error is seen only through ANT deployment. When I deploy the code without WSMyAPI_v1.cls, succefully, and then using dev-console to paste the code from above WSMyAPI_v1.cls file, I dont get any compilation error.

Please advise! 

Regards,
Amit Rangari
Hi,

I would like to understand the way 'states' are retained across batches while using Database.Stateful.

Example, If I am using 'totalSum'  as variable to be maintained across batches, then I could do one of the following.  Which one of below is more optimal? does the SF makes sure that the 'serialization of execution' is done only when the Line 2 in option 2 used about to be executed?, 
if the serialization is across all the body of execution(), then option-1 and option-2 does not look too different.
 
//Option 1

execute (scope) {
   foreach(myObject__c obj: scope) {
       totalSum += obj.field_to_sum__c; //<== Line 1
   }
}
 
//Option 2

execute (scope) {
   Integer localSum = 0;
   foreach(myObject__c obj: scope) {
       localSum += obj.field_to_sum__c;
   }

 totalSum += localSum;  //<== Line 2
}

 
Hi,

I have developed a simple class which refers to the global class defined by the underlying package.  I use the ANT with SF migration tools to deploy the code on my dev-org. I get following compilation error:


classes/WSMyAPI_v1.cls -- Error: Dependent class is invalid and needs recompilation:
(namespace)
namespace.class2 : line 141, column 47: Loop variable must be an SObject or list of object3__c (line 166, column 70)

Please note that this error is seen only through ANT deployment. When I deploy the code without WSMyAPI_v1.cls, succefully, and then using dev-console to paste the code from above WSMyAPI_v1.cls file, I dont get any compilation error.

Please advise! 

Regards,
Amit Rangari