We are facing the problems when running the batch apex getting below error      First error: Update failed. First exception on row 0 with id   0061A000012kKuBQAU; first error: UNABLE_TO_LOCK_ROW, unable to obtain   exclusive access to this record or 156 records   Can any one please suggest how to avoid these error?
25839
Error Message:     Developer script exception from Nicomatic : quotepotential :   quotepotential: execution of AfterUpdate caused by:   System.DmlException: Update failed. First exception on row 0 with id   a0Q90000005PoxtEAC; first error: UNABLE_TO_LOCK_ROW, unable to obtain   exclusive access to this record: [] Trigger.quotepotential: line 14,   column 1      Apex script unhandled trigger exception by user/organization:   00590000001A6jh/00D90000000bovq      quotepotential: execution of AfterUpdate      caused by: System.DmlException: Update failed. First exception on row   0 with id a0Q90000005PoxtEAC; first error: UNABLE_TO_LOCK_ROW, unable   to obtain exclusive access to this record: []      Trigger.quotepotential: line 14, column 1   these mails are getting to my mail..........  trigger quotepotential on Quote_Line_Item__c (after insert,after update) {     Set&lt;Id&gt; quoteIds = new Set&lt;Id&gt;();     List&lt;Quote__c&gt; quotes = new List&lt;Quote__c&gt;();     for (Quote_Line_Item__c record: Trigger.new) {         if (record.Quote1__c != null){             quoteIds.add(record.Quote1__c);         }     }     for(AggregateResult ar:[                 SELECT                      Quote1__c,                      SUM(Max_Batch__c)sumMax                  FROM Quote_Line_Item__c                  WHERE Quote1__c=:quoteIds                  GROUP BY Quote1__c                 ]) {          quotes.add(new Quote__c(              Id=(Id) ar.get('Quote1__c'),              Potential__c = (Decimal) ar.get('sumMax')              ));     }     if (quotes.isempty() == false) {         update quotes;     } }
37067
I am deploying to production using the Ant migration tool. Every class is reporting the error: Apex class has Batchable or Future jobs pending or in progress Even classes such as StringUtils and such which have not future or batchable methods.  Someone asked a similar question here  but it was closed for comment because it was a duplicate of this post:   But that post does not answer my problem.  Nor does the SF posted help here:
89641
I have a need to execute the Apex class every minute.   I have a Sites VF page and in that I have link called "Export to Excel" which exports bulk data (say 50000 records of my wrapper class type) through Batch Apex.  The application is used by about 100 users When more than 5 users click on that link simultaneously (at the same time), or within a minute batch jobs fails.  Am planning to have a custom object and make an entry in it whenever the users click on that link and populate whatever necessary details needed for executing that job and will also have a status column. If the status is yet to process and if the number of running process is less than 5 (or) 3, planning to call an apex batch job and this caller class will be a schedulable type and thought of scheduling it every minute. Unfortunately am unable to schedule it for every minute.   Any ideas for doing a custom implementation for scheduling my job every minute without installing any external apps? Or is there an alternative solution for my problem?
89672
I have two processes which execute code like this in parallel:  begin; update foos set unread=false where owner_id=123 and unread=true; commit;   This results in deadlocks.  My understanding of what causes deadlocks is like the scenario described in , with "interwoven" UPDATE statements updating two different rows in a different order. I don't understand how a single UPDATE statement could result in a deadlock. I'm not able to replicate the deadlock scenario using two parallel psql sessions in my dev environment. My guesses for why I can't replicate it:   I'm misunderstanding my code which creates the deadlock error, and there are actually multiple UPDATE statements in each transaction The "interwoven" aspect is happening, but "within" the UPDATE statement which covers multiple rows, so it's difficult to replicate.   Is it possible for this single UPDATE to be creating the deadlock?
27583
documentation says that      Maximum execution time for each Apex transaction is 10 minutes for   both Synchronous and Asynchronous   To understand this I executed the below code in anonymous apex window :  Long startTime = System.now().getTime(); Long maxLimit = 9*60*1000; //I am taking max limit as 9 mins. while(System.now().getTime() - startTime &lt;= maxLimit ){   }   I get this error :    What is one use case where we don't run into CPU time limit(or other limits) but reach execution time limit?
55805
I am using an APEX batch to process and insert large amounts of data. Essentially I would like it to process every row to catch any errors with the data and then rollback the entire batch if a single error is found. Is there any simple way to do this?  I have tried using a Save Point, but because they are not serialisable, it doesn't work across the entire batch.   Just to clarify, by error I mean an error that I have defined, error with validation, etc. Not an Exception thrown by the system.
76368
How do you stop race conditions in MySQL? the problem at hand is caused by a simple algorithm:   select a row from table if it doesn't exist, insert it   and then either you get a duplicate row, or if you prevent it via unique/primary keys, an error.  Now normally I'd think transactions help here, but because the row doesn't exist, the transaction don't actually help (or am I missing something?).  LOCK TABLE sounds like an overkill, especially if the table is updated multiple times per second.  The only other solution I can think of is GET_LOCK() for every different id, but isn't there a better way? Are there no scalability issues here as well? And also, doing it for every table sounds a bit unnatural, as it sounds like a very common problem in high-concurrency databases to me.
28251
I recently started working on a large complex application, and I've just been assigned a bug due to this error:  ORA-04091: table SCMA.TBL1 is mutating, trigger/function may not see it ORA-06512: at "SCMA.TRG_T1_TBL1_COL1", line 4 ORA-04088: error during execution of trigger 'SCMA.TRG_T1_TBL1_COL1'   The trigger in question looks like       create or replace TRIGGER TRG_T1_TBL1_COL1    BEFORE  INSERT OR UPDATE OF t1_appnt_evnt_id ON TBL1    FOR EACH ROW    WHEN (NEW.t1_prnt_t1_pk is not  null)    DECLARE         v_reassign_count number(20);    BEGIN        select count(t1_pk) INTO v_reassign_count from TBL1               where  t1_appnt_evnt_id=:new.t1_appnt_evnt_id and t1_prnt_t1_pk is not null;        IF (v_reassign_count &gt; 0) THEN            RAISE_APPLICATION_ERROR(-20013, 'Multiple reassignments not allowed');        END IF;    END;   The table has a primary key "t1_pk", an "appointment event id" t1_appnt_evnt_id and another column "t1_prnt_t1_pk" which may or may not contain another row's t1_pk.  It appears the trigger is trying to make sure that nobody else with the same t1_appnt_evnt_id has referred to the same one this row is referring to a referral to another row, if this one is referring to another row.  The comment on the bug report from the DBA says "remove the trigger, and perform the check in the code", but unfortunately they have a proprietary code generation framework layered on top of Hibernate, so I can't even figure out where it actually gets written out, so I'm hoping that there is a way to make this trigger work.  Is there?
85919
While cloning record i am getting the below error in the 1st line of the code, the SOQL. Can anyone help me with that.  XX_Segment__c desc1 = [select  Id, XXX_New_Keyword_Description__r.Description__c from XX_Segment__c where Availability_Forecast_XXX__c =:id1]; String s= desc1.XXX_New_Keyword_Description__r.Description__c; s= s.substring(0,3); String s1 = s+'%';   Regards
37241
I have a Apex batch class which I would like to schedule at a particular date time. The date time is stored in a variable and changes dynamically. ex Datatime scduleDateTime = datetime.now() ; I want to schedule the apex batch file to run at this datetime variable value.  How can I do that using system.scheduleBatch()  I started with this but could'nt see how I can specify a datetime variable in here:  datetime d = datetime.now(); sampleapexbatch b = new sampleapexbatch(d); System.scheduleBatch(b,'Sample Job',XXXXXXXX)   Any help is appreciated!
83646
I'm attempting a mass update on Contacts via Execute Anonymous. My code gives me the following error:     System.LimitException: Apex CPU Time Limit Exceeded   Here's my code:  List &lt;Contact&gt; contactList = [select Id, Mass_Update_Checkbox__c from Contact Limit 1000];  for (Contact contact : contactList) {     contact.Mass_Update_Checkbox__c = TRUE;  }  update contactList;
44444
What else, other than insert/update/upsert/delete, can cause "System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out"?  I've search the debug logs multiple times, and there absolutely is not a DML statement executed between the startTest and the failing callout.  Are there any other commands, or perhaps another callout (even though it's only an inquiry), that can cause this?  Does anyone know how to get around this problem?
70882
Is there a way to configure SQL Server to limit the number of rows than an update statement can modify?  Say I wanted the limit to be 30,000 rows and someone fired an update that would modify 45,000 rows, they would receive an error or some other preventive message.
78453
I have been watching how to implement the batch for sending more than 10 email but I get errors. When I send emails I have a limit 5 and also are sent several times to the same user email  global class SendBatchClass implements Database.Batchable&lt;sObject&gt;, Database.AllowsCallouts{     String query = '';      global Batchname(){     }     global SendBatchClass(String newBodyBatch,...){        this.body = newBodyBatch;        try{...}        catch(){...}     }     global Database.QueryLocator start(Database.BatchableContext BC) {          return Database.getQueryLocator(query);     }     global void execute(Database.BatchableContext BC, List&lt;Contact&gt; scope) {         SES sesEmail = new SES(as3.key,as3.secret);         for(sObject s: scope){             sesEmail.sendEmail(subRecipients,sender,subject,newBody);         }     }     global void finish(Database.BatchableContext BC) {      } }
41171
So I have the following query that I am running through Batch Apex. I get the error:  System.LimitException: Too many query rows: 50001  I am receiving this because COUNT_DISTINCT() is subject to the same governor limits as other SOQL Queries. Basically I cannot think of a solution here, which is why I am posting this. The goal of the query is to see how many unique accounts an SDR is in contact with over a given time period. In this case, it is over a 120 day period. Would love some advice on how to achieve this.  String Contacts_Reached_TR_120_Query = 'SELECT Ownerid SDR_ID, COUNT_DISTINCT( whoid ) result FROM Task Where ActivityDate = LAST_N_DAYS:120 AND OwnerId in :ListOfIDs GROUP BY Ownerid';  DynamicBatchApexAR batch3_TR120      =   new DynamicBatchApexAR('SDR_ID', 'result', 'Contacts_Reached_TR_120__c', Contacts_Reached_TR_120_Query, SDR_IDs);   Then here is the batch class  global class DynamicBatchApexAR implements Database.Batchable&lt;AggregateResult&gt; {  public String sObjectIdKey; public String sObjectResultKey; public String sObjectFieldToUpdate; public String query; public List&lt;Id&gt; ListOfIDs;   global DynamicBatchApexAR(String arIdKey, String arResultKey, String fieldToUpdate, String soqlQuery, List&lt;Id&gt; whereInClause )  {       sObjectIdKey            = arIdKey;     sObjectResultKey        = arResultKey;     sObjectFieldToUpdate    = fieldToUpdate;     query                   = soqlQuery;     ListOfIDs               = whereInClause; }  global DynamicBatchApexAR(String arIdKey, String arResultKey, String fieldToUpdate, String soqlQuery )  {       sObjectIdKey            = arIdKey;     sObjectResultKey        = arResultKey;     sObjectFieldToUpdate    = fieldToUpdate;     query                   = soqlQuery; }  global Iterable&lt;AggregateResult&gt; start(Database.BatchableContext BC)  {     return ListOfIDs == null ? new BulkIterable(query) : new BulkIterable(query, ListOfIDs); }  global void execute(Database.BatchableContext BC, List&lt;sObject&gt; scope)  {     DynamicSObjectUpdater sObjectUpdater = new DynamicSObjectUpdater();      for(sObject sObj: scope)     {          AggregateResult ar      = (AggregateResult)sObj;         ID sObjectId            = (ID)ar.get(sObjectIdKey);         Decimal arResult        = (Decimal)ar.get(sObjectResultKey);         Map&lt;String, Object&gt; sObjectFieldsToUpdate = new Map&lt;String, Object&gt;{             sObjectFieldToUpdate =&gt; arResult         };          sObjectUpdater.getUpdateSObject(sObjectId, sObjectFieldsToUpdate);     }      sObjectUpdater.updateSObjects();   } global void finish(Database.BatchableContext BC)  {  }   }  Here is the iterable    global with sharing class BulkIterable implements Iterable&lt;AggregateResult&gt; {         String query;         List&lt;Id&gt;   ListOfIDs;      global BulkIterable(String soql, List&lt;Id&gt; WhereInClause)     {         query = soql;         ListOfIDs = WhereInClause;     }      global BulkIterable(String soql)     {         query = soql;     }      global Iterator&lt;AggregateResult&gt; Iterator(){         return ListOfIDs == null ? new BulkIterator(query) :  new BulkIterator(query, ListOfIDs);     }  }   Here is the iterator      global class BulkIterator implements Iterator&lt;AggregateResult&gt; {        AggregateResult[] results { get;set; }       Integer index { get;set; }   List&lt;Id&gt; ListOfIDs;      global BulkIterator(String query, List&lt;Id&gt; WhereInClause)      {     index = 0;     ListOfIDs = WhereInClause;     results = Database.query(query);        }    global BulkIterator(String query) {     index = 0;     results = Database.query(query);      }    global Boolean hasNext(){     return results != null &amp;&amp; !results.isEmpty() &amp;&amp; index &lt; results.size();    }        global AggregateResult next() {      return results[index++];   }      }   Is the error because I am running too many batches?
50915
I want to know whether it is practically possible to pass a parameter from first batch apex into second batch apex. I do not want code but a brief concept would be greatly helpful.
494
i have created a schedulable class which has to trigger a batch job. The run method for the batch class will get list of data to process from a webservice callout. Now, i got the exception below. Any suggestions please.     System.CalloutException: Callout from scheduled Apex not supported.   global class scheduledDeltaBatchable implements Schedulable {    global void execute(SchedulableContext sc) {     ID batchprocessid = BatchUpsertSAPCustomerMasterBPSync.run(SAPServices.GetSAPCustomerMasterBPSync('Delta'));    } }