5 件の回答

@abhishek - I love a canned response. If we hope to guide the new programmers, a little explaination will always help rather than just do it this way.@OlgaAlright, to answer the questions,lets review the code and point some things out.1. You have a SOQL query inside a FOR loop. This is an issue for bulkification. There are plenty of posts regarding that issue and how to overcome it.2. Why are you getting the insert error? I would guess to say that that the field is not set in the TEST__c object that you are using as a reference point. If you wanted to find out if this was the cause, throw a debug in the code to test for the value in the field. Or nest the creation of the record in an IF statement to test that the values exist in the TEST__c record.3. You will have future issues. Which is why @abhishek posted the associated links. Even if you get past the error you are experiencing, you will have issues on the insert of the billingLineList. It may not error, but will be an issue. Why? Because of this line:
bill1.AcctSeed__Billing__c=billings2.Id;
The billings2 record has not been inserted. The Id for the record will not exist prior to being inserted. Therefore you will be setting the AcctSeed__Billing__c to null. And so will not have the relationship you are trying to establish.
You could implement a simple piece of code below to prove that Ids do not exist until inserted.
Hopefully that is clear. I would now recommend that you check the links that @abhishek posted and adjust your code. Keep in mind points 1 & 2 above.RegardsAndrewLead beforeLead = new Lead(LastName='Sample',
FirstName ='A',
Company='ACME',
Status = 'Open - Not Contacted',
Email = 'sample@acme.acme');
System.assertEquals(null,beforeLead.Id);
insert beforeLead;
System.assertNotEquals(null,beforeLead.Id);