• luckyme
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 10
    Replies

I have some custom objects for which I set the Name field to be auto number and I want to be able to get the rows in the same order that I wrote them.

 

But to my surprise when I do 'select ... from ... order by Name', it is not working as I expected. For example, row 99 will come after row 100 -- the reason I think is it is ordering as strings not numbers.

 

Note that order by CreatedDate does not work because some rows may have the same value.

 

Of course I do not want to create a number field and maintain a counter myself.

 

Anyone knows how to get around this issue?

 

I am getting this when trying to run any Apex test code. Anyone has any idea?

How come the format method on Decimal always strips trailing zeroes?

 

For example, if

Decimal d = 1234.00;

d.format() => 1,234

 

 

On the UI, Opportunity Product (a child of Opportunity) has Product. But in the schema (or if you use describe), Opportunity Product (or really OpportunityLineItem) does not have Product. Instead, it has PricebookEntry which has Product.

 

We are building a product which needs to expose Product as a field on Opportunity. We want to write the code using 'describe' instead of hardcode it. But then we have to expose the extra object PricebookEntry which may confuse user.

 

Anyone knows why the UI is out of sync with the backend for this?

Anyone knows if I can do something like

select ... from ... where (field1, field2) in {('a1', 'a2'), ('b1', 'b2')}?

 

I am getting a strange error message as above.

 

I have an interface {say A} which has one method. I have a class {say B} that implements the interface (the method). And I have another class/method that takes interface A as a parameter. And I call that method with an instance of the class B. All compiles ok. But I got the error when running it.

 

I do not see what can possibly be wrong with my code. If I do not implement the method in A, it fails to compile. If I remove 'implements A' from B, it fails to compile. Also I have another class {C} that implements the interface A, and is used in exact same way and it works fine.

 

Anyone has seen similar issues?

 

 

 

 

 

 

Currently the finish() method is not called if the query returns no records. I think this is wrong. I think finish() should always be called regardless whether the query returns any records or not. What do you think?

Same code worked fine up til yesterday. Anyone else having same problem? The error is 'no such column ... on entity...' but I do have the field on the object.

 

I am using Batch Apex and found the following behavior: if execute() method is never called (the query returns no records), the finish() method is not called at all. I think this is wrong. The finish() method should always be called. What do you guys think?
I am trying to test batch Apex but got 'Insufficient Privileges'. Anyone knows why or how to fix that?

I have to run few batch apex classes in a sequence. For example I have BatchApex1, BatchApex2 and BatchApex3. I want BatchApex2 to be started only after BatchApex1 is complete.

similarly BatchApex3 should start only after BatchApex2 is complete. please suggest me how can I achieve this.

 

Thanks in advance.

RS

Message Edited by sfdeveloper9 on 12-19-2009 02:23 PM

How come the format method on Decimal always strips trailing zeroes?

 

For example, if

Decimal d = 1234.00;

d.format() => 1,234

 

 

I understand the purpose of the governor limits.  I understand some of the limits themselves, such as heap size.  I do not understand many of them.  One I do not understand is a limit of 1000 for a List. It appears to be an indirect memory limit, which is a duplicate effort since there is already a heap limit, and counterintuitive since one element can be as small as an Integer or as large as a complex blob containing object. 

 

THE QUESTION:  If I need to insert 1600 rows, does this actually mean I have to create two lists, one with 1000 and another with 600 rows, which I then have to execute as two inserts?  Am I understanding this correctly?!?

 

Same code worked fine up til yesterday. Anyone else having same problem? The error is 'no such column ... on entity...' but I do have the field on the object.

 

Hi -

 

I am looking for the fastest way possible to mass delete all records for a given custom object. I developed a very simple Batch Apex class which is described below.  The code works but it performs very slowly. Yesterday it took 40 minutes to delete 34,000 records, although I did not run into any governor limits.  It seems that the execute() call is only receiving a few records at a time.  Is there any way to coax it to process large groups of records?

 

Any help would be greatly appreciated.

 

global class MassDeleteCustomObject implements Database.Batchable<Sobject>

{

  global final String query = 'select Id from <my custom object>';

 

  global Database.QueryLocator start(Database.BatchableContext BC)

  {

 

       return Database.getQueryLocator(query);

  }

 

    global void execute(Database.BatchableContext BC, List<Sobject> records)

   {

        delete records;

   }

 

  global void finish(Database.BatchableContext BC)

  {

  }

 

}

Hi,

 

I have created a batch apex class which assigns leads , opps, accounts to appropriate territories as per territory rules and other business logic.

 

I am clicking on custom button 'Run Rules' in Territory List View and calling the batch apex class and related method using javascript behaviour.

 

Right now, I am just testing for Leads(there are nearly 25K leads). 118 batches run properly while 1 batch fails. The error that it gives as per Debug log is:-

 

20091021124930.554:External entry point:     returning NULL from method global Database.QueryLocator start(Database.BatchableContext) in 0 ms

 This is my snapshot of Apex Jobs processing:-

 

ActionSubmitted DateSorted DescendingJob TypeStatusTotal BatchesBatches ProcessedFailuresSubmitted ByCompletion DateApex ClassApex Method
 10/21/2009 7:49 AMBatch ApexFailed011Desai, Vimal10/21/2009 7:49 AMBatchApexTerritoryAssignmentBulk 
 10/21/2009 7:49 AMBatch ApexCompleted1181180Desai, Vimal10/21/2009 7:53 AMBatchApexTerritoryAssignmentBulk 

 

The batch apex code is:-

 

global class BatchApexTerritoryAssignmentBulk implements Database.Batchable<SObject>
{
  public String query;

 global database.Querylocator start(Database.batchableContext bc)
 {
   Integer cont;
   if(query == null)
   cont = 1;
   else
   cont = 0;
   if(cont == 0)
   return Database.getQueryLocator(query);
   else
   return null;
 }

 global void execute(Database.BatchableContext BC, List<SObject> sobjList)
 {
  System.Debug('DATABASE.BATACHABLE CONTEXT' + BC);
  System.Debug('SOBJECT LIST SIZE PASSED AS QUERY : ' + sobjList.size());
  TerritoryAssignmentBulk tabObj = new TerritoryAssignmentBulk();
  List<Lead> leadList = new List<Lead>();
  Map<Id,Account> accMap = new Map<Id,Account>();
  List<Opportunity> oppList = new List<Opportunity>();
  
  for(sobject s : sobjList)
  {
   if(s.getsObjectType() == Lead.sObjectType)
   {
    Lead l = (Lead)s;
    if(!l.isConverted)
    {
     leadList.add(l);
    }
   }
  }
  System.Debug('LEAD LIST SIZE : ' + leadList.size());
 
  if(leadList.size()!=0)
  {
   tabObj.runRules(oppList, accMap, leadList, false);//The method that needs to be called, for lead all others will be null and boolean false
   update leadList;
  }

  /*for(sobject s : sobjList)
  {
   if(s.getsObjectType() == Account.sObjectType)
   {
    Account a = (Account)s;
    accMap.put(a.id,a);
   }
  }
  if(accMap.size()!=0)
  {
   tabObj.runRules(oppList, accMap, leadList, false);//The method that needs to be called, for lead all others will be null and boolean false
   update accMap.values();
  } */
 }


 global void finish(Database.BatchableContext BC)
 {
 
 }

 webservice static String BatchApexMethod(String objectType)
 {
  BatchApexTerritoryAssignmentBulk leadBulk = new BatchApexTerritoryAssignmentBulk();
  BatchApexTerritoryAssignmentBulk accBulk = new BatchApexTerritoryAssignmentBulk();

  if(objectType == 'Lead')

   leadBulk.query = 'Select Id, Name, Company, Keep_in_Territory__c, LastName, Status, isConverted From Lead where isConverted = false';
  
   System.Debug('QUERY' + leadBulk.query);
  
  Id leadProcessId = Database.executeBatch(leadBulk);

  /*if(objectType == 'Account')

   accBulk.query = 'Select Id, Name From Account';
  
  Id accountProcessId = Database.executeBatch(accBulk); */
 
  return '';
 } 
}

 

The custom button code is :-

 

{!requireScript("/js/functions.js")}

{!requireScript("/soap/ajax/13.0/connection.js")}

{!requireScript("/soap/ajax/13.0/apex.js")}



try

{

var acc = "Account";

var lead = "Lead";

var opty = "Opportunity";



sforce.apex.execute("BatchApexTerritoryAssignmentBulk", "BatchApexMethod", {a:acc});

sforce.apex.execute("BatchApexTerritoryAssignmentBulk", "BatchApexMethod", {a: lead});

sforce.apex.execute("BatchApexTerritoryAssignmentBulk", "BatchApexMethod", {a: opty});



}



catch(e)

{

alert(e);

}

Hi,

 

I am just trying to write a test method for my class and I am getting the error:

 

 

Method does not exist or incorrect signature: Test.StartTest()

 

Does anyone know what might cause this? I have tried this in a blank class to ensure its not caused by any other code but I still get the same error.

 

Cheers

 

James 

 

 

Hi All,

 

Getting quite frustrated with trying to find a solution for this issue.

 

Using Batch Apex and it is intermittently working correctly.

 

I have raised a case #03007660 ... however lucky me has had it assigned to someone out of office (that's the email reply I got anyway).

 

See my code below.

 

I have tried and tested it with batches of up to 327 records and it has worked successfully. However now trying to test with larger batches of >3000 records all I get is a debug log that says see below. And my Apex Jobs log just says..

 

Job Type = Batch Apex

Status = Completed

Total Batches = 0

Batches Processed = 0

Failures = 0

 

Essentially nothing happens. No error no real message nothing. Any help would be much appreciated here, I've seen a few other posts with similar issues, however this is getting critical for me to find a solution! 

 

I have also tried 'chunking' the batches at varying intervals all the way from 25 - 200 in the 'execute' method, without any success and also as another post suggested added a 'limit' to my query which also didn't help.

 

SOQL locator query with 3324 rows finished in 608 msCumulative resource usage:Total email recipients queued to be sent : 0Stack frame variables and sizes:  Frame0

 

global class PaymentCreate implements Database.Batchable<SObject>{// Creates and Processes Payments
public date PSBD;
public String PSID;
public String PSM;
Public String query;
global database.querylocator start(Database.BatchableContext BC){
  return Database.getQueryLocator(query);
}

global void execute(Database.BatchableContext BC, Sobject[] scope){
  List<AcctPayments__c> PaymentHolder = new List<AcctPayments__c>();
  List<Recurring_Payment__c> batchRP = new List<Recurring_Payment__c>();
  for(sobject s : scope){
    Recurring_Payment__c p = (Recurring_Payment__c)s;
    PaymentHolder.add(new AcctPayments__c(Payment_Session__c = PSID, Contact__c = p._Contact__c, Payment_Total__c = p.Recurring_Amount__c, Auto_Allocate__c = true, Payment_Method__c = PSM, RP_ID__c = p.Id, RP__c = p.Id, Recurring_Payment_Processed__c = true));
    p.MEMforce__Last_Processed__c = PSBD;
    batchRP.add(p);
  }
  insert PaymentHolder;
  update batchRP;
}

global void finish(Database.BatchableContext BC){
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setReplyTo('batch@batch.com.au');
mail.setTargetObjectId(UserInfo.getUserId());
mail.setSaveAsActivity(false);
mail.setSenderDisplayName('Batch Processing - Payments Updated (Loaded and Processed)');
mail.setSubject('Batch Process Completed - Payments Updated (Loaded and Processed)');
mail.setPlainTextBody('Batch Process has completed - Payment Updated (Loaded and Processed)');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
 //INVOKE
     loading.query= myQuery;     loading.PSID = thisPS.Id;
     loading.PSBD= thisPS.Banking_Date__c;
     loading.PSM = thisPS.Payment_Method__c;
     ID batchprocessid = Database.executeBatch(loading, 50);
Message Edited by Patrick Bulacz on 10-15-2009 09:36 PM

My test coverage is 100% but average is 86% with 1 failure...

I dont understand this error:

System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Record Type ID: id value not valid for the users profile: {0}: [RecordTypeId]

 

I do not understand ...