You need to sign in to do that
Don't have an account?

Line: 1, Column: 24 Unexpected token '('.
HI,
I am trying to call my method in the anonymous window but it is showing me (Line: 1, Column: 24 Unexpected token '('.) this error. The class is static so it is not necessary to make an object or instance of that class..
AccountContact.onBefore(Account Name='asdf');
This is my code i am inserting an account with the account name
I am trying to call my method in the anonymous window but it is showing me (Line: 1, Column: 24 Unexpected token '('.) this error. The class is static so it is not necessary to make an object or instance of that class..
AccountContact.onBefore(Account Name='asdf');
This is my code i am inserting an account with the account name
You are calling the method with incorrect parameter.
Use this code this will help you to call the method from anonymous window.
If you found it useful please appreciate my efforts and mark it as the best answer
Regards,
Soyab
All Answers
Can you please put your static class code, so I can help you.
Regards,
Soyab
public static void onBefore(List<Account> acctList){
List<Contact> conList = new List<Contact>();
for(Account acc: acctList){
Contact con = new Contact(AccountId = acc.ID);
List<String> nameStr = acc.Name.split(' ');
if(nameStr.size()>0)
con.LastName = nameStr[0];
if(nameStr.size()>1)
con.FirstName = nameStr[1];
con.FirstName = 'Info';
con.LastName = 'Default';
con.Email = 'info@websitedomain.tld';
acc.OnlyDefaultContact__c = TRUE;
conList.add(con);
}
insert conList;
}
public static void updateCheckBox(List<Contact> contList){
Set<id> accountIds = new Set<id>();
for(Contact con: contList){
accountIds.add(con.Accountid);
}
List<Account> updateAccount = new List<Account>();
for(AggregateResult ar: [Select count(id), AccountId from Contact where AccountId IN
: accountids group by AccountId having count(id)>1]){
updateAccount.add(new Account(id = (id)ar.get('Account Id'),OnlyDefaultContact__c
= FALSE));
}
}
}
You are calling the method with incorrect parameter.
Use this code this will help you to call the method from anonymous window.
If you found it useful please appreciate my efforts and mark it as the best answer
Regards,
Soyab
acc.OnlyDefaultContact__c = TRUE; .. How can we access this fileld.. When i am runnig my code the conatct is created but the checkbox doesnt get checked. But when i am calling like this con.OnlyDefaultContact__c = TRUE; which is i think is incorrect the it trown an error variable does not exist..