New answers tagged

0

Ah well I can vote and wait 10 years


2

The hint given by Chris Peterson in the comment helped me solve it. It was the userId used in notification.send(userId); It was set to UserInfo.getUserId() which in the context of the BatchApexErrorEvent trigger was an Automated Process. When I changed it to the user that kicked of the Batch by querying [SELECT CreatedById FROM AsyncApexJob WHERE Id event....


1

According to your comment, your issue is knowing how to create the map used in the query. Batchables can contain class attributes like any other Apex class. These values are available for use in the start, execute and finish method implementations, even without implementing Database.Stateful (the latter allows the values of these attributes to be updated in ...


0

Got it! There was validations not showing, so I added pricebook data and pricebookentry data that was missing as well as using a different user that would populate the one formula field. Once that was completed I am testing out 100 % on both classes. Thanks again for the second set of eyes as that allowed me to continue to troubleshoot and find the root ...


1

The error seems to be in the query string. You are using double-quotes " character which is not recognized by the apex, it only recognizes single-quote '. There are several ways you can fix this. Use ' escaped character String strQuery = 'SELECT Id, CloseDate, StageName, Owner.Email FROM Opportunity WHERE CloseDate < TODAY AND StageName != \'5. Won - ...


1

Since you don't describe the use case here, I'd suggest this as a validation rule on the Account object to prevent the data from being set incorrectly in the first place. Formula: AND ( Property_Managment_Company__c = 'Independent', NOT(ISBLANK(ParentId)) ) Error Message: This account is independently managed and cannot have a parent account specified ...


0

I am not sure why you are creating new instance of Account object inside for loop. But you can try following code: for(Account acc : lstAc){ if (acc.Property_Managment_Company__c == 'Independent') { acc .ParentId = null; } } update lstAc;


2

In these situations, it helps to know which fields you do have access to. The SOAP API documentation is where I tend to turn to. In the SOAP API docs for LoginHistory, we see that there is a UserId field, which is a reference to User. User does contain ProfileId, which is what you're after. So your query's WHERE clause would look something like WHERE User....


1

Batch jobs do not share state. A Stateful batch retains its state only through its own conclusion, and has no access to any other batch's state. Your only option to compare results across batch job runs is to persist that state to the database and programmatically perform a comparison. If you are storing this value in an object, you can query that object (...


1

You could consider storing the csvString value and job id to the db during each batch run. Then in each batch run do a lookup by jobid to see if the csvString value is changing. Be careful to avoid comparing dates because async batches can run at an undetermined time. An approach might be to compare “whether the csvString value has changed since the last ...


2

First of all, you must wrap your batch invocation in Test.startTest() and Test.stopTest(), or your asynchronous code will not run inside the context of your unit test. See How do I test asynchronous Apex? for more details. Then, you must write assertions about what you believe to be true of the data in listAcc after your code has run. The reference for the ...


0

You forgot to insert the records you were creating: ALN_Integration__c[] alnIntegrationRecords = new ALN_Integration__c[0]; for (ALN_Integration__c recAln : lstCon) { AccountContactRelation acr = new AccountContactRelation(); acr.AccountId = accPmcMap.get(recAln.Property__c).Id; acr.ContactId = conMap.(recAln.First_Name__c + recAln.Last_name__c + ...


2

Don't use try-catch; use a partial-update pattern instead. NOTE: This code is not technically bulkified (createOrUpdate needs to be bulkified if any queries are involved); it is meant to be illustrative. public void execute(Database.BatchableContext context, Object1[] scope) { Object2[] recordsToUpsert = new Object2[0]; for(Object1 recordToProcess: scope)...


Top 50 recent answers are included