So my code basically looks like below
public with sharing class test_exists {
Public Map<Id, Case> cases;
public static void start_creation(Map<String, Account> acc){
cases = New Map<Id, Case>();
for (String s: acc.keyset()){
Account c_acc = acc.get(s);
Case new_case = new Case(AccountId = c_acc.Id, Name=c_acc.Name);
cases.put(c_acc.Id, new_case);
}
}
}
I'm getting two errors
Variable does not exist:
cases
Method does not exist or incorrect signature:
void.put
- and I've chalked this up to cases not actually being initialized and thus it's still null.
I've also tried
public with sharing class test_exists {
Public Map<Id, Case> cases{get;set;}
public test_exists(){
cases = New Map<Id, Case>();
}
public static void start_creation(Map<String, Account> acc){
for (String s: acc.keyset()){
Account c_acc = acc.get(s);
Case new_case = new Case(AccountId = c_acc.Id, Name=c_acc.Name);
cases.put(c_acc.Id, new_case);
}
}
}
but I'm still getting the same error of "Method does not exist or incorrect signature: void.put
"
Might the fact that I'm calling New within the constructor be the source of the problem? I've done similar things such as assigning to a previously declared variable without problems.
Edit:
The class above is being called from a trigger which has access to a bunch of other classes.
I removed the static keyword as suggested below and now from within the trigger code there is an error of 'Non static method cannot be referenced from a static context: void test_exists.start_creation(Map)'
Does that mean that acc as is being passed in has to be a static?
static
keyword actually does. Without further explanation of what you're trying to accomplish with this class of yours, I doubt that astatic
method is what you want. Please go into more detail about what exactly it is you're trying to accomplish in your trigger.