I am loading a CSV file via Static Resourced to test my APEX code. I am using the following code in my test:
List<Territory_Zip_Code__c> territoryData = Test.loadData(Territory_Zip_Code__c.sObjectType, TERRITORY_ZIP_CODES_STATIC_RESOURCE_NAME);
The first few lines of the CSV file look like so:
Territory__c,Zip_Code__c
ABC,123
DEF,456
I am getting the following error:
System.StringException: Unknown field: Territory__c
Territory__c is a valid API field name for my custom sObject.
I've also tried adding the sObject name in front of the field name, like My_Territory__c.Territory__c but that didn't work either.
In addition, I tried using the field name, instead of the API name (for example, Territory) but that didn't work either.
There are lots of examples of using Test.loadData with built-in sObjects, such as Account and Contacts, but no examples showing custom sObjects. I'm starting to think this just isn't possible with custom objects.
Using test.loadData most certainly does work with custom objects. The test data CSV header only needs the field names, as you have in your example.
Your code also looks good. The only difference I could spot is that your variable is a strongly typed list. In my code I use a List which seems to work:
List<sObject> testdata = Test.loadData(MyCustomObject__c.sObjectType, 'mytestdatafile');
Related
I'am trying to hide the Json value of the student field from log files using filter-spec,
this is my filter-spec :
after i applied the flter this is how the data is showing in the log file
all i want it is to replace ("student" : "testStudent") with ("student": "****") instead it is got replaced with ("student: ****)
does anyone have an example on how to hide the json value using filter-spec?
Thanks in advance
It is not actually possible replace a JSON value with a filter. You'd need to use a custom filter or custom handler in order to do this.
You could file a feature request though. It does seem like a decent idea for a filter to be able to filter values in structured formats.
I am doing an HTTP GET request to /maximo/oslc/os/mxsr and using the oslc.select query string parameter to choose:
*,doclinks{*},worklog{*},rel.commlog{*},rel.woactivity{*,rel.woactivity{*}}
This lets me get related data, including related worklogs, but the worklog does not include the 'description_longdescription' field.
The only way I seem to be able to get that field is if I do a separate HTTP GET to query a worklog id directly through /maxrest/rest/mbo/worklog . Then it provides the description_longdescription field.
I understand this field is stored separately through the linked longdescription table, but I was hoping to get the data through the "next gen" oslc api with one http get request.
I've tried putting in 'worklog{*,description_longdescription}', as I read somewhere that longdescription is a "non-persistent" field and must be explicitly named for inclusion, but it had no effect.
I figured out that for the /maximo/oslc/os/mxsr object in the API, I needed to reference the related MODIFYWORKLOG object through the rel.modifyworklog syntax in the oslc.select query string:
oslc.select=*,doclinks{*},rel.modifyworklog{*,description_longdescription},rel.commlog{*},rel.woactivity{*,rel.woactivity{*}}
I also had to explicitly name the non-persistent field description_longdescription for it to be included.
Ref. for the "rel." syntax: https://developer.ibm.com/static/site-id/155/maximodev/restguide/Maximo_Nextgen_REST_API.html#_querying_maximo_asset_management_by_using_the_rest_api
I have a build up a report with a .CSV input file as DataAdapter. After that I needeed a table to put some data into a it and a linked dataset. The problem is: if I leave blank the section "Default Data Adapter" in my Dataset1, no data will be displayed. In fact, to fix this report I had to export my DataAdapter as myDataAdapter.xml and then put this file in the section "Default Data Adapter" of my Dataset1 (as shown in the attached picture).
Working with database I have never set up this property.
Is there a way to pass this property as Param? (I have a java code in which I call jasperReport and I want to pass this object dinamically).
Or is there a way the report works without setting this property?
In the section Table>Dataset I have this situation:
where I set up JRDatasource expression, but it is not working...
I have one more problem. Can I set dinamically the location of my .csv inside the DataAdapter.xml?
Is it possible to implement "myDataAdapter.xml" from java code and pass it to the report??
Thank you in advance!
In Java code you can set properties on the net.sf.jasperreports.engine.JasperReport instance like in this sample here, from the official repository. The relevant code looks like this:
...
JasperReport jasperReport = ...
...
jasperReport = (JasperReport)JRLoader.loadObjectFromFile("build/reports/ExcelXlsxQeDataAdapterReport.jasper");
jasperReport.setProperty(DataAdapterParameterContributorFactory.PROPERTY_DATA_ADAPTER_LOCATION, "data/XlsxQeDataAdapter.xml");
...
The property of interest is net.sf.jasperreports.data.adapter and is stored in DataAdapterParameterContributorFactory.PROPERTY_DATA_ADAPTER_LOCATION
The data adapter file is a convenience method to pass a series of parameters from which a net.sf.jasperreports.engine.data.JRCsvDataSource is built. If you want to skip passing this property, you would have to manually provide the built-in parameters listed in the net.sf.jasperreports.engine.query.JRCsvQueryExecuterFactory.CSV_BUILTIN_PARAMETERS.
I was following the answer in this stack overflow question. But I couldn't get the output I am expecting to get. I have a sample csv, which looks like this:
id,name,city
12,Jimmy,Ontario
33,Kimmel,York
Every city has a unique code, which I have stored in another csv.This is how my csv to be used to map looks like. (I have separated the two values in the row using a tab in the real txt file)
California 5435
Ontario 2342
York 3456
The final output must be like the following:
id,name,city,code
12,Jimmy,Ontario,2342
33,Kimmel,York,3456
This csv has much more data therefore the replacement cannot be achieved by using ReplaceText Processor. So it can be done only by using the ReplaceTextwithMapping Processor.
I have followed the exact steps used as an answer in this question. But it seems like the Replace TextwithMapping is not working as expected. Since a new column is made successfully. But it's just contains the same content of the city column not the codes I want.
Its greatly appreciated if you could submit an answer that I can follow to finally succeed in getting the desired output using ReplaceTextwithMapping Processor
I could make it work kind of using LookupRecord. The overall flow looks like this:
GenerateFlowFile:
LookupRecord:
Configure CSVReader and CSVRecordSetWriter to treat the first line as header line. For the other properties leave the defaults. Configure CSVRecordLookupService:
The mapping file has following content:
city,code
Ontario,2342
California,5435
The LookupRecord processor will take the city value and lookup the proper record from the mapping file. It will extract the code and add the field to the current record. Result:
As you can see the code has been added to the CSV file. However it is enclosed in an object, although I have selected Insert Record Fields setting. I could not solve this problem. This could be another question to ask explicitly.
I have a google chart and want to add a custom tooltip. I found some great answers like this this site and set about doing this with roles. I also found this link about it and it looked like the best way.
My data is being generated via json and I use a php file to create a json feed. The rows I have coded like this
{"cols": [ {"id":"","label":"Period","pattern":""},
{"id":"","label":"Recorded P/L","type":"number", "role":"data"} ,
{"id":"","label": null,"type":"string", "role":"tooltip"},
{"id":"","label":"Best Available P/L","type":"number", "role":"data"},
{"id":"","label": null,"type":"string", "role":"tooltip"}
]
Then it goes on and adds all the data. The problem is when I try to run this I get the error
All series on a given axis must be of the same data type
I have checked the json and that is formed correctly but am not sure what I could be doing wrong.
At least part of your problem is that you're not specifying the type for your first column.