Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: heap size error and invalid field check
Browse files Browse the repository at this point in the history
  • Loading branch information
pozil committed Jun 20, 2023
1 parent 25aea83 commit 849e08f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2,008 deletions.
14 changes: 7 additions & 7 deletions force-app/main/default/classes/CsvToObjectTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public with sharing class CsvToObjectTest {
LIMIT 1].Body;

String scriptName = 'csvToCustomObject';
DataWeave.Script dwscript = DataWeave.Script.createScript(scriptName);
DataWeave.Result dwresult = dwscript.execute(new Map<String, Object>{'records' => data.toString()});
DataWeave.Script script = DataWeave.Script.createScript(scriptName);
DataWeave.Result dwresult = script.execute(new Map<String, Object>{'records' => data.toString()});

// Note that CsvData here is an Apex POTATO (Apex equivalent of a POJO)
List<CsvData> results = (List<CsvData>)dwresult.getValue();
Expand Down Expand Up @@ -46,14 +46,14 @@ public with sharing class CsvToObjectTest {
System.debug(LoggingLevel.Warn, 'Before parse CPU: ' + Limits.getCpuTime() + '/' + Limits.getLimitCpuTime());

String scriptName = 'csvToCustomObject';
Dataweave.Script dwscript = DataWeave.Script.createScript(scriptName);
DataWeave.Result dwresult = dwscript.execute(new Map<String, Object>{'records' => data.toString()});
Dataweave.Script script = DataWeave.Script.createScript(scriptName);
DataWeave.Result dwresult = script.execute(new Map<String, Object>{'records' => data.toString()});

System.debug(LoggingLevel.Warn, 'After parse Heap: ' + Limits.getHeapSize() + '/' + Limits.getLimitHeapSize());
System.debug(LoggingLevel.Warn, 'After parse CPU: ' + Limits.getCpuTime() + '/' + Limits.getLimitCpuTime());

List<CsvData> results = (List<CsvData>)dwresult.getValue();
Assert.areEqual(20000, results.size());
Assert.areEqual(18000, results.size());

System.debug('Heap: ' + Limits.getHeapSize() + '/' + Limits.getLimitHeapSize());

Expand All @@ -63,8 +63,8 @@ public with sharing class CsvToObjectTest {
Assert.isNotNull(c.Company);
Assert.isNotNull(c.Address);

if(c.FirstName=='Donette' && c.LastName=='Foller') {
Assert.areEqual('34 Center St\r\n#42', c.Address);
if(c.FirstName=='Vinnie' && c.LastName=='Martellini') {
Assert.areEqual('Schulist, Schneider and Gutkowski', c.Company);
}
}

Expand Down
2 changes: 1 addition & 1 deletion force-app/main/default/dw/csvToCustomObject.dwl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ output application/apex
records map(record) -> {
FirstName: record.first_name,
LastName: record.last_name,
Company: record.email,
Company: record.company_name,
Address: record.address
} as Object {class: "CsvData"}
Loading

0 comments on commit 849e08f

Please sign in to comment.