0

I have two Apex classes that differ by literally only their name. Here's MaintenanceRequestBatch.cls:

public with sharing class MaintenanceRequestBatch implements Database.Batchable<sObject>{
    public List<Id> ids;

    public MaintenanceRequestBatch(List<Id> ids) {
        this.ids = ids;
    }

    public Database.QueryLocator start(Database.BatchableContext context) {
        return Database.getQueryLocator('SELECT Id FROM Case WHERE ID in :this.ids');
    }

    public void execute(Database.BatchableContext context, List<Case> cases) {}

    public void finish(Database.BatchableContext context) {}
}

Here's Batch.cls:

public with sharing class Batch implements Database.Batchable<sObject>{
    public List<Id> ids;

    public Batch(List<Id> ids) {
        this.ids = ids;
    }

    public Database.QueryLocator start(Database.BatchableContext context) {
        return Database.getQueryLocator('SELECT Id FROM Case WHERE ID in :this.ids');
    }

    public void execute(Database.BatchableContext context, List<Case> cases) {}

    public void finish(Database.BatchableContext context) {}
}

Here's the diff on those two files:

1c1
< public with sharing class Batch implements Database.Batchable<sObject>{
---
> public with sharing class MaintenanceRequestBatch implements Database.Batchable<sObject>{
4c4
<     public Batch(List<Id> ids) {
---
>     public MaintenanceRequestBatch(List<Id> ids) {

Now I have a third class, MaintenanceRequestHelper that's supposed batchify an operation. Here's what it looks like first.

public with sharing class MaintenanceRequestHelper {
    public static void updateWorkOrders(List<Case> cases) {
        List<id> ids = new List<Id>();
        for (Case oneCase : cases) {
            ids.add(oneCase.Id);
        }
        Batch b = new MaintenanceRequestBatch(ids);
    }
}

If I try to deploy this, I get the following error:

SOURCE PROGRESS | █████████████████████████████████████░░░ | 11/12 Components
TYPE   PROJECT PATH                                                 PROBLEM
─────  ───────────────────────────────────────────────────────────  ────────────────────────────────────────────
Error  force-app/main/default/classes/MaintenanceRequestHelper.cls  Invalid type: MaintenanceRequestBatch (7:19)
ERROR running force:source:deploy:  Deploy failed.

But if I change the word MaintenanceRequestBatch in line 7 above, I get no error.

        Batch b = new Batch(ids);

I think I must be missing something obvious. I've been copying and pasting to make sure everything is exactly the same except for the class name and therefore constructor name. How can changing that one thing give me an invalid type?

1
  • What happens if you do MaintenanceRequestBatch b = new MaintenanceRequestBatch(ids);? – Nick Cook Jan 27 at 1:54
2

The thing that jumps out to me is the following line

Batch b = new MaintenanceRequestBatch(ids);

Your MaintenanceRequestBatch class does not extend your Batch class, so that assignment is invalid (the types are not compatible).

How that would generate an invalid type compile-time error, I'm not sure. I would think you should be getting an illegal assignment error instead.

1
  • You're right, I should have caught that, but fixing that problem didn't change the error I get when I attempt to deploy (well, changed it slightly, the error's being reported at character 9 now instead of character 19). – Chuck Jan 27 at 20:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.