You need to sign in to do that
Don't have an account?
MontTwo MontTwo
I become Errors like "Argument can not be null", "List has no rows" or "Update failed"... What can I do with that?
Test Roll-Up Summary field with MIN Decimal for Data calculating
Hello. I tried everything in this test. I really don't know, how to do that right.
I have 3 Objects:
- A has a Number (Decimal) field.
- B has a Lookup field to A, Master-Detail to C and Number field for Number from A (I used Process Builder to get the Number).
- C has Roll-Up Summary: it calculates MIN value from all Number fields from B with C in Master-Detail.
My code:
public class Helper { public static void upd(Map<Id, Case> cases){ //Case is C-object List<Case> newCases = new List<Case>(); for(Case caseOld : cases.values()){ Date date = Date.today().addMonths(Integer.valueOf(caseOld.Min__c)); //Min__c is Roll-Up Summary field Case caseNew = new Case(Origin = 'Web', Status = 'New', Date_Due__c = date); newCases.add(caseNew); } insert newCases; } }My Test fragment:
List<Case> newCList = new List<Case>(); Case cs = [SELECT Min__c FROM Case]; for(Integer i=1; i<20; i++){ Date date = Date.today().addMonths(Integer.valueOf(cs.Min__c)); Case c = new Case(Origin = 'Web', Status = 'New', Date_Due__c = date); newCList .add(c); } insert newCList; System.assertEquals(20, newCList.size());I used everything: adding in test objects A and B, inserting and this:
Case cs1 = new Case(Origin = 'Web', Status = 'New'); insert cs1; Case cs = [SELECT Min__c FROM Case WHERE Status = 'New']; for(Integer i=1; i<20; i++){ Date date = Date.today().addMonths(Integer.valueOf(cs.Min__c)); Case c = new Case(Origin = 'Web', Status = 'New', Date_Due__c = date); newCList .add(c); } insert newCList; System.assertEquals(20, newCList.size());Roll-Up Summary isn't writable.
I become Errors like "Argument can not be null", "List has no rows" or "Update failed"... What can I do with that?
I solved a problem :)
All Answers
<pre>
Case testCase = new Case();
insert testCase;
ObjectB__c testB = new ObjectB__c( Number__c = 1, Case__c = testCase.Id );
insert testB;
Case cs = [SELECT Min__c FROM Case WHERE Id = :testCase.Id];
// cs.Min__c should now equal 1
</pre>
I solved a problem :)