New answers tagged

0

I had the exact same problem and I found the solution as a scheduled apex batch class only. Batch Class global class BatchLoginData implements Database.Batchable<sObject>{ public string sQuery; public string ProfID = '00e5w000000k5JMAAY'; global Database.Querylocator start (Database.BatchableContext BC){ sQuery = 'SELECT Id, ...


0

This is an ideal use case for a Set. Here's an optimized version to get you started: global Database.QueryLocator start(Database.BatchableContext context) { return Database.getQueryLocator([ SELECT OwnerId FROM Account ]); } global void execute(Database.BatchableContext context, Account[] scope) { // Track Account.OwnerId + Task.OwnerId ...


2

I am assuming your batch uses a Query Locator, rather than an iterator. There's an interesting blog that looked into how fresh or stale batch data is. Whilst it is quite old now, a rather interesting point it covers is: Originally, the way this worked was that the data was queried in the start, and the entire query results (all the queried fields) put into ...


2

I have several batch jobs that I used to schedule. For example, one job had to be executed 10 times per hour, so I scheduled it at 02, 08, 14, ... minutes after the hour. Usually the time between those executions was long enough, so that no overlap could occur. Sometimes overlap did occur, but in this case that was not disastrous. Then a disaster happened: ...


0

We experienced the penalty delays for chained Queueables in the past (although documentation is rubbish with regards to this). We have 8-10 chained Queueables at times and the AsyncApexJob entries would show a ~60s delay between Completion and Creation but we have not seen these delays for a while now (I would say at least since 1 year ago).


1

The null variable assignment that you found may be a red herring. The system probably assigns null to 'kes' when the function runs, and/or perhaps when the loop or function finishes. There are lots of null assignments that happen behind the scenes to avoid invalid pointer problems that you see in other languages, and may explain what you're seeing in the log....


2

As folks in the comments have said, you're likely to hit limit issues if the volume is sufficiently high. There are two solutions I've used for this. The first solution sounds close to what you're trying to do, so I'll present it first. The second I've found to be more reliable, but it may take some refactoring on your part. First solution is to use a ...


0

Do you have a reason why you want to use a batch to send emails when the articles are published and their status changes? Why a batch and not a Process Builder or a Record-triggered Flow or an Apex Trigger? If you are very sure you want to send your emails from a batch, then maybe you can combine these mechanisms, e.g. use a Record triggered Flow to detect a ...


3

Bind variables e.g. :kesIds are a good way to go because they leave the type conversion formatting up to the framework and in the process also eliminate the SOQL injection risk. And make your code simpler and much easier to read. But the variable must be in scope - visible to the code - at the point that Database.query executes as illustrated in Rijwandeltax'...


0

Set<ID> accId = new Set<ID>(); accId.add('0016F00002QHh3E'); String query = 'Select id from Account Where ID IN :accId'; for(Account acc : Database.query(query)){ System.debug('acc=>'+acc); } Its working for me You only need to set keyids variable global variable


1

If you look at the schema, you can see that KnowledgeArticleVersionHistory is not related to the Knowledge__kav. Instead it is related (via ParentId lookup field) to the Knowledge__ka object (which is the parent of all Knowledge Article versions.


2

I think you need to enable Track Field History for the Knowledge object. If "Track Field History" is not enabled for the Knowledge object, actions will not show on new Knowledge Article versions and also for previous versions even if 'field history' was enabled when that version was created. If it is enabled, actions will show to new versions and ...


1

You can use below CRON expression. 0 0 12 ? 1/1 SAT#1 * I just tested this in my org and it seems working. You can use http://www.cronmaker.com/?1 to generate this easily in future.


1

You need to implement the Database.Stateful interface and declare an instance variable to keep its state. If you declare it as static, it doesn't maintain its state across batch jobs. https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm


0

Keep in mind that test classes do not execute queries on your database unless you specify the SeeAllData=true parameter is @IsTest annotation (which is not a best practice, but sometimes useful). I think that the error is given because no Account is being extracted from your query. Try inserting some sample data in a @TestSetup annotated method and then ...


0

There's nothing in this code that would cause that error; you don't even need the LIMIT 50000 in your code, assuming your intent is to update all records that need to be updated: return Database.getQueryLocator( [Select Fax,MobilePhone,Email,Account.Phone,Account.Fax,Account.Name,Account.Rating from contact] ); Your code confuses || for ...


2

Conversion is easy, just change the first few lines of your class: global class Non_OLMP_Last_Course_Check implements Schedulable { global void execute(SchedulableContext ctx) { Map<ID,hed__Program_Enrollment__c> program_Enrollments = new Map<ID,hed__Program_Enrollment__c>([Select Id, Name, hed__Enrollment_Status__c,...


2

You can't break the limit, so your options are basically to either do the callout in the execute method, or use Queueable so you can call it repeatedly until all pages are retrieved: public class MyQueueable implements Queueable, Database.AllowsCallouts { ExternalCustomerAPI syncPoint = new ExternalCustomerAPI(APISettings__c.getInstance('API ...


2

The problem isn't really the remote API - it's the design of your CalloutOne and CalloutTwo classes. With the logging DML in the position that it is, you can never call these classes more than once in a transaction. Consider a different pattern. For example, you could pass in a Map<Id, List<Some_Logging_Record__c>> instance and let both callout ...


1

When your code is scheduled, the private properties you've defined are stored for later use. Therefore, they will never be updated, and only update users that met the criteria when the scheduler was initially scheduled. Move the variables to the start method: global Database.QueryLocator start(Database.BatchableContext BC) { DateTime LoggedInPast2Hours ...


1

EDIT: 0 0 * * * ? is the correct cron expression as sfdcfox pointed out. Read as "the first second of the first minute of every hour of every day of the month of every month (with the question mark being used to ignore the Day_of_week)" I should do a better job of looking at the Salesforce documentation, they lay out the template right there: ...


2

global List<Sales_Data_Aggregated__c> listSalesDataAggregated_Upsert = new List<Sales_Data_Aggregated__c>(); global List<Sales_Data_Aggregated__c> listSalesDataAggregated_Delete = new List<Sales_Data_Aggregated__c>(); These two variables should be reset for each execution of the execute method. In fact, they should be in the local ...


0

I ended up getting around the query row limit issue by creating Rollup fields on the Opportunity to summarize OpportunityLineItems. Even though the lookup to Opportunity on OpportunityLineItem is not labeled a Master-Detail relationship in Salesforce, you are in fact able to create Rollup fields to summarize it, which is what got me past my issue.


1

It's to do with the serialization of the stateful property List<Exception>. Although the Exception class is generally serializable, some of its subclasses are not. (you could say there are exceptions to this) DmlException being one of them. (EmailException is also). Try these in the dev console, to see what I mean. JSON.serialize(new ...


Top 50 recent answers are included