Hot answers tagged

16

For the variables in stateful class in whom you don't wanna store state, you can make those variables as transient. Use the transient keyword to declare instance variables that can't be saved, and shouldn't be transmitted as part of the view state for a Visualforce page. You can also use the transient keyword in Apex classes that are serializable, ...


6

Since you already have a list of Ids (AcLst) you could query every Opportunity related to those Accounts, then populate a Map using the accountId as key and the list of opportunity as value. Map<Id, List<Opportunity>> mapAccountIdOpportunityList = new Map<Id, List<Opportunity>>(); for (Opportunity o : [SELECT Id, StageName, AccountId,...


6

Setup | Deployment Settings | Allow deployments of components when corresponding Apex jobs are pending or in progress. Caution: Enabling this option may cause Apex jobs to fail. The above applies to deploying into a target org If you are developing in a sandbox, and you are editing an apex class that is used in a running job of that sandbox, you need to ...


4

The entire update will fail. From Apex Developer Guide - Apex Transactions: All DML operations in a transaction either complete successfully, or if an error occurs in one operation, the entire transaction is rolled back and no data is committed to the database. The boundary of a transaction can be a trigger, a class method, an anonymous block of code, a ...


3

There is no way to load more than a total of 50K records in a given synchronous session/transaction (as per the documentation), and certainly no way to do this in a trigger. The only way to deal with this sort of thing is to use async processing such as in a Batchable as you mentioned. It is possible to execute certain types of aggregate query across more ...


3

Change the class signature: public with sharing class APTS_UsageInput_InsertTempRecordsBatch implements Database.Batchable<APTS_UsageInputWrapper> Make sure you consistently apply "generics" in your Batchable implementation, as covered in the documentation: public Iterable<APTS_UsageInputWrapper> start(Database.BatchableContext context) and:...


3

In documentation we have an example with private final String initialState; variable. This batch class does not implement Database.Stateful. Maybe you should just remove final keyword because we implement this interface and mark this variable as public? Also, investigate this article. It could be helpfull.


3

You don't need nested iteration here. There's no reason to iterate over the keys of the inner Map. While you could make that work, you'd end up with a complex if/else or switch on statement inside the inner for loop. It's much easier to directly access the inner Map keys whose values you require. It'd look something like this: for (String s : ...


3

One class is not the same as another, even if it has the same name. However, you can modify your batch to simply use the first's: Map<String,StudentFileQuable.ErrorClassToSend> errorMap = new Map<String,StudentFileQuable.ErrorClassToSend>(); Alternatively, you could pull out the class into its own top-level class, since it's to be shared ...


2

In the case of an exception in a trigger, all records involved in that trigger will not be updated, regardless of if allOrNone is set, because Salesforce cannot determine which records were successful. Triggers are synchronous in nature. The "before update" and "after update" simply refers to the half-way point initial commit phase. This initial commit is ...


2

There might be specific known issue in specific version of Salesforce API if issue occurs on Production but isn't seen in Sandbox. For example, if your production has winter 19 release and sandbox has spring 20 release, the issue may exist in Winter 19 and may be fixed in spring 20. First of all, open Salesforce support case to find out root cause and ...


2

If System.abortJob is not working for you, make sure you update the Deployment Settings on the org allowing updates to Apex that has pending jobs, edit the batch to remove the chaining and re-deploy (or edit via setup) your batch code. It will then stop once the current instance has finished.


1

ld.Id is null because you aren't really inserting it. List<Lead> Leadld = New List<Lead>(); lead ld = new lead(); ld.RecordTypeId = '012p0000000Nn05AAC'; ld.Company = 'Google'; // ... snipped ... insert Leadld; The Lead object ld is not in the list Leadld, which is empty. Your insert therefore does nothing, and ld.Id ...


1

I don't think you need a batch class for this. At the data volume you mentioned I expect somewhere between 100-200 records for Country. and maybe 500-1000 records for City you should be able to handle this with a couple of quick queries and run updates: Map<Id, Continent__c> continentsToUpdate = new Map<Id, Continent__c>(); // First, find ...


Only top voted, non community-wiki answers of a minimum length are eligible