Notifications
Clear all
Sep 07, 2021 2:05 pm
Here I am skipping the records for which there is no matching count__c.
I need to concatinate a string (skippedRecords) with ids of those skipped records. How would I achive this?
List<Parent__c> parentList = [SELECT Id, Name,downloads__c FROM Parent__c WHERE count__c IN :countList]; List<Data__c > datatoupdate = new List<Data__c >(); String skippedRecords = ''; for(Data__c dRecords : dList) { for(Parent__c parentRecords : parentList) { if(dRecords.count__c == parentRecords.count__c) { dRecords.downloads__c = parentRecords.downloads__c ; datatoupdate.add(dRecords ); } } } update datatoupdate;
1 Reply
Sep 07, 2021 2:07 pm
Ended up creating this:
String skippedRecords = ''; Integer checkedParentIds = 0; Boolean idMatch = false; Integer totalParentIds = parentList.size(); for(Data__c dRecords : dList) { idMatch = false; totalParentIds = parentList.size(); checkedParentIds = 0; for(Parent__c parentRecs : parentList) { checkedParentIds++; if(dRecords.count__c == parentRecs.count__c) { dRecords.downloads__c = parentRecords.downloads__c; ddRecsToInsert.add(dRecords); idMatch = true; break; } else if ((checkedParentIds == totalParentIds) && (idMatch == false)) { skippedRecords += dRecords.count__c + '\n'; } } }