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;


}

...
  • Can you add some code that illustrates your issue? – sfdcfox Feb 24 '14 at 17:00
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);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.