You need to sign in to do that
Don't have an account?
Invalid constructor syntax, name=value pairs can only be used for SObjects
the above error i am getting wen i am executing thi program..... plz help me
public with sharing class ChatterUnitTests {
/*
* Test the ChatterActivity trigger which inserts chatter feed posts whenever a task is inserted on the parent object
*/
public static testMethod void testChatterActivity() {
//create the test account
Account a = new Account(name='Test Account');
insert a;
//create a task on that account
Task t = new Task(whatId=a.id);
t.Subject = 'This is a test activity for chatter';
t.ActivityDate = System.today();
t.Status = 'In Progress';
t.Description = 'Hello, this will be chattered';
insert t;
//Make sure Account has the feed enabled. If it does, make sure the chatter feed post is there
Schema.DescribeSObjectResult r = Account.SObjectType.getDescribe();
if (r.isFeedEnabled()) {
List<AccountFeed> posts = [SELECT Id, Type FROM AccountFeed WHERE ParentId = :a.id];
System.assertEquals(1, posts.size());
}
}
}
Hi,
I think you are getting an error on this line: Task t = new Task(whatId=a.id);
You can rewrite it as,
Task t = new Task();
t.whatId = a.Id;
Thanks,
Devendra
Since the error says name value pair for contructor the issue might be because of the overriding of standard controller with custom, just check your org for any custom controller with name Account or Task. If you find any just try renaming them to something else or delete the controller if you dont need it.
Now try saving the code where you got the error. Hope it helps
--yvk
Thanks yvk431!
I have got this issue many times, But first time i have got the solution.
Yes, It's Working after Renaming Account or deleting Account Name from controller
Thanks for the advice. That just fixed my problem concerning "Invalid constructor syntax, name=value pairs can only be used for SObjects." I eliminated the custom controller and the problem went away!
thanks for your advice! it's really appreciated and helpful a lot. When I struct at the error.