0

I am writing unit tests for some code that I wrote last month.

Given this code:

    private static void generateTestData() {
        HeddySummaryForProfileImport__c testSummary = new HeddySummaryForProfileImport__c();
        testSummary.Name = 'testSummary name'; 
        testSummary.ProfileId__c = '999999'; 
        testSummary.ProfileType__c = 'company'; 
        testSummary.Body__c = 'testSummary body'; 
        testSummary.Title__c = 'testSummary title'; 
        insert testSummary;
        Id testSummaryId = testSummary.Id;

        return testSummaryId; 
   }

I get this error:

Illegal assignment from void to Id

I assume this about this line:

    Id testSummaryId = testSummary.Id;

but this comes right after an "insert". I thought the "insert" set the Id for the object?

1

Ah, the problem was with the "void" in the function signature, held over from an earlier version. I changed this to Id.

2
  • Odd that it would even compile
    – Eric
    Nov 24 '16 at 8:41
  • I agree. I actually had several strange cases where I used the Force CLI and ran "force import" and got a bunch of error messages, then fixed all the error messages, and so I thought the code was compiled and working. Yet when I ran the tests, I got additional errors such as this. I wonder if Force CLI runs all the checks that I assume? Perhaps not?
    – LRK9
    Nov 24 '16 at 17:43

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.