You need to sign in to do that
Don't have an account?
return sObject method - record type question
I am buldiing a test class with sObjects instantiated inside a test factory. I have another accountTest class that passes parameters to the test class which successfully created my account with buildTestAccountPostive(). However, in my negative test, I want to be able to update this same account with and set the record type to null. First of all, will SFDC let me update a account.recordtypeId = null and is there a way I can insert an Account succesfully without any recordtypeID?
Second question if yes, when I try to reference the newAccount1 with Account negAccountRec =[select id, recordtypeid from Account where ID IN: newAccount1]; i keep getting newAccount1 variable does not exist. Notice Account buildTestAccountPostive() is not static
public Account buildTestAccountPostive(Integer i)
{
Account newAccount1 = new Account();
newAccount1.Name = 'Test' + i;
//RT is hard-coded temporarily ill update to use a collection instead later
newAccount1.recordtypeid= '012f0000000ChWYAA0';
return newAccount1;
}
public static Account updateTestAccountPositivetoNegative(Integer i)
{
Account negAccountRec =[select id, recordtypeid from Account where ID IN: newAccount1];
negAccountRec.recordtypeid = null;
return negAccountRec;
}
sfdcls:
1. The reason that newAccount1 is not found is because your second method doesn't declare it. These routines could be much simpler such as the following:
2. I believe that recordTypeId = null is the MasterRecordType for the SObject. It will only be settable if the SObject has at least one custom recordTYpe defined.
3. And, avoid hard coded recordTYpeIds -- use a SOQL Select to fetch the IDs and reference using the developerName field.
BTW - I highly recommend the SFDC Workbench tool as a vehicle for trying out SOQL and inspecting your org - it is a good way to learn more about the SFDC 'system-y' SObjects. Also the API Reference Guide has full details on each SObject.