12
votes
Accepted
Generate xlsx file from Apex
You're not going to be able to use XLSX at all. It's based on the Office Open XML standards from Microsoft. Basically, it's a set of XML files contained in a ZIP file, of which we have no native means ...
10
votes
Generate xlsx file from Apex
I know the question has already been answered but to anyone who stumbles upon here looking for other options, I found a solution that generates an actual .xlsx file using only Apex. Take note though ...
8
votes
Accepted
send a Report as a CSV/TEXT through HttpRequest
You can get the contents of the report by using a PageReference:
String reportText = new PageReference('/'+reportId+'?csv=1').getContent().toString();
From there, you can send the data to your ...
7
votes
Accepted
CSV created with first row as empty. Any suggestions please
i am trying to create a csv and succeeded in that except with a new
empty row has been added on the top of the csv. The following is the
visualforce page code for the generation.
You need to make ...
6
votes
Accepted
Checking fields for Blank or Null
If the Business_Partner_Identifier_Code__c entry is of type string you can use:
String s = String.isBlank((String) record.get('Business_Partner_Identifier_Code__c'))
? ''
: String....
6
votes
How to split a string by the newline character in Apex?
Try \n:
myInput.split('\n');
If your input uses \r\n, that is another common option.
myInput.split('\r\n');
6
votes
Accepted
Making a string in apex class bold?
That's not how CSV files work. Comma Separated Values means that the file contains tabular data values in plain text. Values only. No formatting.
Note that the below solution is the only way to ...
6
votes
Accepted
Loop through comma separated values in Visual Flow
Sure you can. Roughly the steps would go like this.
Create a screen element with a long text area input field.
Link it to a decision element to see if the field is empty. If it's not (shouldn't be ...
6
votes
Accepted
Handle Extra "\r\n" new line in CSV from code level
Basically, you should call a replaceAll beforehand:
contents = contents.replaceAll('(\r\n|\r)','\n');
This code normalizes CRLF and CR to use just LF. Note that CSV may be in any of those three ...
6
votes
bulk api text/csv CRLF error
change the Request body of Job Creation as follows.
{
"operation" : "insert",
"object" : "Product2",
"contentType" : "CSV",
"lineEnding" : "LF"
}
It worked for me.Also ensure that the ...
6
votes
Most robust way to parse CSV file via Apex code
Given that CSV's have a reasonably simple format defined in RFC 4180 it can be surprising complicated to actually implement a parser that is both correct to the spec and efficient for larger CSV files....
5
votes
CSV Parser for 'Importing large CSV files via Batch Apex '
Try this ImportCSVJob class as a reference implementation of Database.Batchable and Schedulable. The class demonstrates how you can use CSVReader to read CSV data, construct new records and then ...
5
votes
Import excel csv data using apex class
Providing the CSV files are not too big, you can use a Visualforce apex:inputFile to upload the file and then apply this Parse a CSV with Apex sample code to grab the data from the rows.
If the CSV ...
5
votes
How to split a string by the newline character in Apex?
In windows you can use split method in other format. Use below example
variable.split('\\n');
or
variable.split('\\r\\n');
Explanation:
Since Salesforce implements Java Pattern class, the meta-...
5
votes
Accepted
VisualForce MultiLine UTF-8 CSV
OK, I have a plausible solution for Excel for Mac users.
First, the options that I considered but rejected:
Windows-1252 encoding - Doesn't support Asian languages
UTF-16LE encoding - Creates user ...
5
votes
Accepted
Read through small CSV file returns Regex too complicated
The regex too complicated error occurs when you reach 1,000,000 input sequences, which can occur even on incredibly small strings. For example, accord to the knowledge article:
Pattern pat = Pattern....
5
votes
Accepted
Parse JSON to CSV and vice versa
Here's a very simple CSV parsing demo from papaparse:
import { LightningElement } from 'lwc';
import { loadScript } from 'lightning/platformResourceLoader';
import PAPA from '@salesforce/resourceUrl/...
4
votes
Accepted
Recurrent CSV import?
In our Salesforce org, we created an inbound email service. This let's us create a special email to be sent to us with an attached file. We then process the file via Apex and do associated work on ...
4
votes
Recurrent CSV import?
I'm not sure if you are aware of this but you can automate Data Loader. Here is a great article to how to do that. If you say that it will always be a .CSV file than this might be a good solution.
4
votes
Unable to display UTF-8 character in a csv file generated from apex code
Here is a better approach...You can actually set a Byte Order Marker at the beginning of the .csv that will allow Excel to open the file correctly. Adding this marker is really very easy. Just add ...
4
votes
Email Attachment (CSV) Issue
This appears to be classic Microsoft Excel behavior when confronted with UTF-8 text. Excel likes to interpret a valid UTF-8 bytestream as if it were encoded in Windows Codepage 1252 or other encodings....
4
votes
Accepted
Create CSV from SOQL query
This could be a misinterpretation of the UI.
You need to click on the download icon
4
votes
How to parse a CSV file into JSON using APEX?
Inspired by this code, fixed up by Daniel Ballinger, I wrote this version, which returns a list of Maps. It turns out that in order to have decent performance, you have to write it in a really ...
4
votes
Accepted
SSJS Automation Studio - Read imported CSV file
In order to do this, you will need to import that file into a Data Extension first. None of Marketing Cloud's scripting languages (SSJS, AMPscript, SQL, or GTL) can touch the SFTP or anything on it. ...
3
votes
Is it possible to populate a field of type Auto Number External ID?
No, this is not possible, because Auto-Number fields are never writable in Salesforce.
This could lead you in serious trouble, especially if you need to do data migrations at some point in the future....
3
votes
Recurrent CSV import?
Salesforce does have several data oriented API's, of which the bulk api can work with csv's directly. But you may be better of parsing the csv before sending the data to salesforce. What strategy fits ...
3
votes
Visualforce Error System.TypeException: Invalid decimal:
I have encountered this problem and founded that when the number column is the last one in the Excel sheet, the system (salesforce) will throw an error: "invalid integer\decimal". Maybe its because it ...
3
votes
Accepted
One day less than original date while uploading data in salesforce
Make sure you specify the timezone when importing date/time fields.
You can read more about this here:
https://help.salesforce.com/HTViewSolution?id=000004680&
3
votes
Accepted
How to create a new record from a CSV file attachment processed by the email service in salesforce
My New code to read and insert data from a csv file using the salesforce email service
Global class CSVFileDataImportEmail implements Messaging.InboundEmailHandler
{
Global string nameFile{get;...
3
votes
Issue while uploading CSV file with embedded comma within column
FWIW, this is a CSV parser with testmethods that I located from a blog post (which no longer exists) - There could easily be better ways of doing this but it handles embedded commas and double quotes. ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
csv × 260apex × 110
visualforce × 27
data-loader × 25
marketing-cloud × 19
import × 16
data-export × 14
attachment × 13
string × 13
upload × 13
soql × 12
batch × 12
excel × 10
dataextensions × 9
bulk-api × 9
lightning-web-components × 8
javascript × 8
unit-test × 8
email × 8
lightning-aura-components × 7
date × 7
data-import × 7
data-import-wizard × 6
lightning × 5
reporting × 5