You need to sign in to do that
Don't have an account?
Ranadheer ch
I had written a test class for the following class....but am getting this error
I wrote a test class for the following class ...but while saving am getting this error Whats wrong in my code...thanks
Error Error: Compile Error: Invalid constructor syntax, name=value pairs can only be used for SObjects at line 8 column 32
my test class
@isTest
private class TestAccountcontactroleClass{
@isTest
private static void testClass()
{
//Standard controller of Accountcontactrole
//Create a new instance of Accountcontactrole
AccountContactRole accs = new AccountContactRole(Account.Name = 'TestAccountName',Role='Newrole',IsPrimary='True' );
//Insert the object virtually
insert accs;
//Create a new instance of standard controller
ApexPages.StandardController sc = new ApexPages.standardController(accs);
AccountContactRoles controller = new AccountContactRoles(sc);
}
}
My class
public with sharing class AccountContactRoles {
private final Contact acr;
public AccountContactRoles(ApexPages.StandardController controller){
this.acr = (Contact)controller.getRecord();
}
public List<AccountContactRole> acrs {
get {
if (acrs == null) {
acrs = [Select Id, Account.Name,
Role, IsPrimary
From AccountContactRole
Where ContactId=:acr.Id
];
}
return acrs;
}
private set;
}
}
I need help ...thanks in advance
Error Error: Compile Error: Invalid constructor syntax, name=value pairs can only be used for SObjects at line 8 column 32
my test class
@isTest
private class TestAccountcontactroleClass{
@isTest
private static void testClass()
{
//Standard controller of Accountcontactrole
//Create a new instance of Accountcontactrole
AccountContactRole accs = new AccountContactRole(Account.Name = 'TestAccountName',Role='Newrole',IsPrimary='True' );
//Insert the object virtually
insert accs;
//Create a new instance of standard controller
ApexPages.StandardController sc = new ApexPages.standardController(accs);
AccountContactRoles controller = new AccountContactRoles(sc);
}
}
My class
public with sharing class AccountContactRoles {
private final Contact acr;
public AccountContactRoles(ApexPages.StandardController controller){
this.acr = (Contact)controller.getRecord();
}
public List<AccountContactRole> acrs {
get {
if (acrs == null) {
acrs = [Select Id, Account.Name,
Role, IsPrimary
From AccountContactRole
Where ContactId=:acr.Id
];
}
return acrs;
}
private set;
}
}
I need help ...thanks in advance
One more thing.
IsPrimary is a boolean, you should use only true.
Also pass the Contact in ApexPages.StandardController.
Check the below one.
All Answers
Try Like below.
You cannot instantiate an inner class like sObjects.
One more thing.
IsPrimary is a boolean, you should use only true.
Also pass the Contact in ApexPages.StandardController.
Check the below one.
Error: Compile Error: Invalid constructor syntax, name=value pairs can only be used for SObjects at line 13 column 32.
Any way thanks for ur help
When instantiate inner class for defined constructor, directly set the parameter such as
new WrapperObject(param1,param2,...) instead of new WrapperObject(property1=param1,property2=param2,...)