You need to sign in to do that
Don't have an account?
saikrishna rangineni
Inserting Phone field in account record from method instance.
This is my Class
public class AccountHandler {
public static Account insertNewAccount(String name,INTEGER Phn) {
Account a = new Account();
a.Name = name;
a.phone = 'Phn';
try
{
insert a;
} catch (Exception e) {
return null;
}
return a;
}
}
Calling from Execute Anonymous
AccountHandler.insertNewAccount('RKNN',12345);
In Account record page iam getting Phone field value as Phn . Instead of 12345 , which i had passed in method. How to get phone field value as 12345 as passed in execute anonymous block.
public class AccountHandler {
public static Account insertNewAccount(String name,INTEGER Phn) {
Account a = new Account();
a.Name = name;
a.phone = 'Phn';
try
{
insert a;
} catch (Exception e) {
return null;
}
return a;
}
}
Calling from Execute Anonymous
AccountHandler.insertNewAccount('RKNN',12345);
In Account record page iam getting Phone field value as Phn . Instead of 12345 , which i had passed in method. How to get phone field value as 12345 as passed in execute anonymous block.
So, you have to pass phone number as String instead of Integer as below.
Then calling from anonymous as below:
Please check and let me know if it helps. If it helps mark it as best answer.
Regards,
Navin S
All Answers
Remove the quotes in the variable like below,
a.phone = Phn;
If you put quotes, then compiler will consider it as string.
Thanks,
Govindaraj.S
Please find below code.
From Execute Anonymous Window, Please use the below code as your code.
Please mark it as the best answer if it helps you.
Best Regards,
Navin S
When i saved class as specified by you, means removing quotes('') to phn. Iam getting a error as Illegal Assignment from Integer to String.
When I removed quotes('') to phn. Iam getting a error as Illegal Assignment from Integer to String.
So, you have to pass phone number as String instead of Integer as below.
Then calling from anonymous as below:
Please check and let me know if it helps. If it helps mark it as best answer.
Regards,
Navin S
Thank you so much. It works fine.
Regards ,
Saikrishna.