function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sfdc newbiesfdc newbie 

Error: variable industrty does not exist

Could any one help y iam getting error in my test class

@isTest
private class ChatterAnswersCreateAccountTest {
    static testMethod void validateAccountCreation() {
        Profile[] p = [SELECT Id FROM Profile WHERE UserType = 'Standard'];
        User[] user = [SELECT Id, Firstname, Lastname FROM User WHERE IsActive = true and ProfileId =: p[0].Id];
        // We cannot create account without a user.
        if (user.size() == 0) { return; }
        String firstName = user[0].FirstName;
        String lastName = user[0].LastName;
        String userId = user[0].Id;
        String accountId = new ChatterAnswersRegistration().createAccount(firstName, lastName, Industry, userId);
        Account account = [SELECT name, Industry, ownerId from Account where Id =: accountId];
        System.assertEquals(firstName + ' ' + lastName, account.name, account.Industry);
        System.assertEquals(userId, account.ownerId);
    }
}
Nilesh Jagtap (NJ)Nilesh Jagtap (NJ)
I would suggest to check Field Level Security for Industry Field on Account.
Looks like it is hidden for some of the profiles.

Thanks,
N.J
sfdc newbiesfdc newbie
it is visible to all profiles
Nilesh Jagtap (NJ)Nilesh Jagtap (NJ)
OK. Looks like industry is missing while creating test account.
Change you code to
@isTest
private class ChatterAnswersCreateAccountTest {
    static testMethod void validateAccountCreation() {
        Profile[] p = [SELECT Id FROM Profile WHERE UserType = 'Standard'];
        User[] user = [SELECT Id, Firstname, Lastname FROM User WHERE IsActive = true and ProfileId =: p[0].Id];
        // We cannot create account without a user.
        if (user.size() == 0) { return; }
        String firstName = user[0].FirstName;
        String lastName = user[0].LastName;
        String userId = user[0].Id;
        String Industry = 'HealthCare';
        String accountId = new ChatterAnswersRegistration().createAccount(firstName, lastName, Industry, userId);
        Account account = [SELECT name, Industry, ownerId from Account where Id =: accountId];
        System.assertEquals(firstName + ' ' + lastName, account.name, account.Industry);
        System.assertEquals(userId, account.ownerId);
    }
}

If this helps you mark this as best answer.

Thanks,
N.J
sfdc newbiesfdc newbie
Now it is getting an error like 

Error: Compile Error: Method does not exist or incorrect signature: [ChatterAnswersRegistration].createAccount(String, String, String, String) at line 12 column 61
Nilesh Jagtap (NJ)Nilesh Jagtap (NJ)
Looks like your code need to be reviewd.

If you are trying to test account creation you can do
@isTest
private class ChatterAnswersCreateAccountTest {
    static testMethod void validateAccountCreation() {
        Profile[] p = [SELECT Id FROM Profile WHERE UserType = 'Standard'];
        User[] user = [SELECT Id, Firstname, Lastname FROM User WHERE IsActive = true and ProfileId =: p[0].Id];
        // We cannot create account without a user.
        if (user.size() == 0) { return; }
        Account oAccount = new Account();
        oAccount.name = 'TestAccc';
        oAccount.Industry = 'HealthCare';
        insert oAccount;
        Account account = [SELECT name, Industry, ownerId from Account where Id =: oAccount.Id];
        
        System.assertEquals('TestAcc', account.name);
    }
}

Thanks.
sfdc newbiesfdc newbie
i replaced above code with most recent code u given.

and added all required fields eventhough iam getting an error like

System.AssertException: Assertion Failed: Expected: TestAcc, Actual: TestAccc

at the line System.assertEquals('TestAcc', account.name);

and one more doubt System.assertEquals(userId, account.ownerId); is not required ?
Nilesh Jagtap (NJ)Nilesh Jagtap (NJ)
Hi
Replace line no 14 with System.assertEquals('TestAccc', account.name);
You can add multiple Asser depending on your requirement.

Thanks.