1

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

I am trying to upsert a List of objects which has a Master-Detail relationship with Account. The objects being the Detail and Account is the master. I do not know how to even fill that Account field, but the field should match the account Id, for the account detail page I am on. Anyone know what is going on?

...
private void Data()

DetailList = [
        SELECT Id, Name, Account__c
               FROM Account_Detail__c LIMIT 900

            ];

public void Detail(){

Data();

    Account_Detail__c j = new Account_Detail__c;

    for(loops over a certain amount of times)
    {

            Account_Detail__c j = new Account_Detail__c();
            j.name ='blank';

            detailList.add(j);


    }

    upsert DetailList;


}

...
1
  • 1
    Can you add some code that illustrates your issue?
    – sfdcfox
    Feb 24, 2014 at 17:00

1 Answer 1

2

You need to set the Account on the new Account_Detail__c records. Try do something like this:

for(Account a : loops over a certain amount of times) {
    Account_Detail__c j = new Account_Detail__c();
    j.name ='blank';
    j.AccountId = a.Id;
    detailList.add(j);
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .