You need to sign in to do that
Don't have an account?
dlCamelot
Transform String Return to Row Return
I'm trying to create a wrapper for my row return but I somehow need 2 classes to accomplish this. I've only successfully written one of the classes which returns a string. How do I take this new query - and make it into a wrapper?
New dnbData2 query:
Old Class that only returns a string:
New dnbData2 query:
dnbData2 = [SELECT companyID, Name, DunsNumber,City,State,Country,Zip FROM DatacloudDandBCompany WHERE Name IN : nameFragments LIMIT 50];
Old Class that only returns a string:
Public class Foobar{ @AuraEnabled public static List<String> getDnBMatches(String companyName){ List<String> dnbFinalMatchList = new List<String>(); List<String> dnbCompleteMatches = new List<String>(); List<String> dnbPartialMatches = new List<String>(); List<String> nameFragments = new List<String>(); List<DatacloudDandBcompany> dnbData2 = new List<DatacloudDandBcompany>(); Integer emptyList = 0; Map<id,DatacloudDandBcompany> dnbData = new Map<id,DatacloudDandBcompany>(); if (String.isBlank(companyName)){ system.debug('DC - No Company Name'); return null; }else{ for (String fragment : companyName.split(' ')){ nameFragments.add(fragment); system.debug('DC - Fragments - ' + nameFragments); } dnbData2 = [SELECT companyId, Name FROM DatacloudDandBCompany WHERE Name IN :('Deloitte','Consulting') LIMIT 50]; system.debug(dnbData2); for (DatacloudDandBCompany c: dnbData2 ){ if (companyName == c.name){ dnbCompleteMatches.add(c.companyid); system.debug('DC - dnbComplete Matches Loop'); } dnbPartialMatches.add(c.companyid); system.debug('DC - dnbPartial Matches Loop'); } if (dnbCompleteMatches.size() > emptyList) { system.debug('DC - dnbComplete Matches Loop' + dnbCompleteMatches); return dnbCompleteMatches; } else { return dnbPartialMatches; } } } }Please note, I have to keep the data manipulation in the new version (i.e. string fragment work, complete and partial results additions, etc.)
I am assuming that dnbData2 variable is a list that holds a records of type DatacloudDandBCompany. Sample code to create an populate a wrapper class is as below. You can then use the dataCloudWrapperList to perform any further processing as required.
Additionally, you can read about using inner classes using the following link - https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_defining.htm
Please do not forget to mark this thread as SOLVED and answer as the BEST ANSWER if it helps resolve your issue.
1. Copy the following within your Foobar class
- Inner class - DatacloudWrapper
- Property - dataCloudWrapperList
- Method to populate the wrapper - buildWrapperList()
2. The code within the buildWrapperList() method, remains the same. The only thing that you would need to do is replace the SOQL query with an appropriate List that has the processed or filtered data to be populated into a list of wrapper.
In case you are unable to pass the wrapper to your UI or client side code on the page, you could use the JSON.serialize() method in Apex to convert the wrapper into a string and pass it back to the UI. Refer the following link to understand more about JSON.serialize() - https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_System_Json.htm.
Please do not forget to mark this thread as SOLVED and answer as the BEST ANSWER if it helps resolve your issue.
Hence, modify line # 5 within the above code to pass the Company Name or an empty string as '' and that should fix the issue for you. The modified code for line # 5 is as below. You can replace 'Sample Company Name' with a value that is more relevant in your case.
Please do not forget to mark this thread as SOLVED and answer as the BEST ANSWER if it helps resolve your issue.