Search code examples
cloudsalesforceapex-code

Required field missng Error


Can someone have a look at it. Below is the code and the error

global void execute(
Database.BatchableContext BC,
List<sObject> listObj){

    list <Account> inAcc = new list<Account>();
    for (sObject lo : listObj){
        Unprocessed_Agreement__c temp = (Unprocessed_Agreement__c)lo;
        inAcc.add(processor.processAccountRecord(temp));
        }
    insert(inAcc); // This line throws the error
    }

the processor class looks something like this

global class CreateAndModifyProcessor {
global Account processAccountRecord( Unprocessed_Agreement__c temp){
    Account tempAcc = new Account();
    tempAcc.Begining__c = temp.Begining__c;
    tempAcc.Agreement_ID__c = temp.Agreement_ID__c;
    return tempAcc; 
}
}

First error: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Name]: [Name]


Solution

  • The Name field is required on accounts, as it is on almost all standard objects in Salesforce. In the same way that you cannot create an account through the ui without a name, you cannot insert account records without giving them a name by setting the Name field like so:

    Account acc = new Account();
    acc.Name = 'Some Name';
    database.insert(acc);