You need to sign in to do that
Don't have an account?
Rohan S
Error: Compile Error: Variable does not exist: Employees at line 8 column 17
I'm writing a trigger on Account, where on creation, if Employees > 1000, a Contact record should be created. Even though the 'Employees' field is present by default in an Account page, it shows the following error: Error: Compile Error: Variable does not exist: Employees at line 8 column 17. Funny thing is if I change the criteria with any other field (like BillingCountry='ABC'), it throws no error. Below is the Apex class:
public class CreateAccountContactClass {
//Declare Contact Creation function
public static void CreateAccountContact (list<Account> AccountsList)
{
list<Contact> ContactsList = new list<Contact>();
for(Account VarA : AccountsList)
{
if(VarA.Employees > 1000)
{
Contact VarC = New Contact();
VarC.FirstName = 'Admin';
VarC.LastName = 'General';
VarC.AccountId = VarA.id;
ContactsList.add(VarC);
}
}
insert ContactsList;
}
}
public class CreateAccountContactClass {
//Declare Contact Creation function
public static void CreateAccountContact (list<Account> AccountsList)
{
list<Contact> ContactsList = new list<Contact>();
for(Account VarA : AccountsList)
{
if(VarA.Employees > 1000)
{
Contact VarC = New Contact();
VarC.FirstName = 'Admin';
VarC.LastName = 'General';
VarC.AccountId = VarA.id;
ContactsList.add(VarC);
}
}
insert ContactsList;
}
}
Try the following code it may be helpful for you:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
All Answers
Try the following code it may be helpful for you:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
Try replacing your if condition: 'THIS' VarA.Employees > 1000 'WITH' VarA.NumberOfEmployees
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi