13
votes
Connect apex and Google API using JWT to retrieve Oauth 2.0 token
As of Winter '17 there are new JWT methods baked in to Apex.
One hoop you have to jump through is getting your key from Google into a Java keystore (JKS) file. Some general info on getting a JKS file ...
8
votes
Accepted
Unable to read ANSI file in apex code?
I hacked a Apex Charset encoder/decoder util, check gist Charset.cls
/**
* Convenience method that decodes bytes in charset into a string of Unicode
* characters.
* <p>
* @param input ...
5
votes
Connect apex and Google API using JWT to retrieve Oauth 2.0 token
For a properly formatted JWT to be generated, it's important to note that this line of code:
JWT = JWT.replaceAll('=','');
Needs to be changed to this:
JWT = JWT.replaceAll('=','');
JWT = JWT....
4
votes
Accepted
How to pass API endpoint URL containing \ to
I strongly suspect that something is going sideways because you're not properly escaping the non-safe URL characters (like \ and [); in a URL, they must be in a certain style known as "percent ...
3
votes
Convert application/octet-stream in E-mail Processing class
There are multiple things that can cause this behavior.
1) You might have set the email service to accept attachments in only 'Binary attachments only'. If you that is the case then your issue may ...
3
votes
Accepted
HmacSHA256 encoding in salesforce
Apparently I made a mistake in the conversion.
So here's the right conversion method.
The issue was that the HMC was a string representation of a HEX so I had to parse it down
Here's the correct ...
3
votes
Accepted
Upload .csv file to salesforce without converting its original encoding
Try this code. It will help you.
oppList = new List<opportunity>();
HttpRequest tmp = new HttpRequest();
tmp.setBodyAsBlob(csvFileBody.body);
csvAsString = tmp.getBody();
...
2
votes
Accepted
Encoding and Decoding BLOB due to error 'BLOB is not a valid UTF-8 string'
Encoding and decoding is just wasting time; the transformation is lossless and won't wipe out invalid characters. It's possible that you have an extra attachment incoming (e.g. if you have an inline ...
2
votes
Accepted
File saved using ContentVersion appears distorted or low quality
`EncodingUtil.urlDecode((String)data.get('file'), 'UTF-8')`
wasn't necessary. decoding just this (String)data.get('file') was the right way.
2
votes
Accepted
Attachment content is empty
This file looks like a legitimate PNG file fragment when saved and downloaded. Reading through the file, we see:
tag
length
data
Magic
8
iVBORw0KGgo= // PNG HEADER
IHDR
13
Width = 1678, Height = ...
1
vote
how to 'encode' the body in an HTTP body?
In Apex Code, \ is a source code escape character. That means to get a literal \, you need to type \\ instead. For this reason, among others, I always prefer to use JSON.serialize; it takes more code, ...
1
vote
Encoding and Decoding BLOB due to error 'BLOB is not a valid UTF-8 string'
Same as previous answer, but added other BOM:
Blob csvBlob = [...];
// Remove BOM //
String encoded = EncodingUtil.convertToHex(csvBlob);
Blob decoded = EncodingUtil.convertFromHex(
encoded
....
1
vote
How to get Base64 String from Binary String or UTF-8 String
You can't start with a UTF-8 string in Apex; by then, the damage has already been done by UTF-8 string conversion. Instead, use FileReader readAsDataURL to get a base-64 encoded version of the file, ...
1
vote
Accepted
HttpRequest Converting > to?
.replaceAll('=','%3D') should instead be EncodingUtil.urlEncode(... ,'utf-8'). This will make sure that all characters are properly encoded.
1
vote
Accepted
Comparing Message Authentication Codes in Apex
Just use EncodingUtil.base64Encode on both Blob values and compare them as (case-sensitive) strings.
String ourMac = EncodingUtil.base64Encode(Crypto.generateMac(...));
String theirMac = ...;
Boolean ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
encodingutil × 25apex × 16
crypto × 6
blob × 4
base64 × 4
character-encoding × 4
attachment × 3
httprequest × 3
csv × 2
blob.topdf × 2
encoding × 2
hashcode × 2
visualforce × 1
lightning-aura-components × 1
trigger × 1
lightning-web-components × 1
community × 1
api × 1
oauth2 × 1
pdf × 1
salesforce-id × 1
files × 1
apex-email-service × 1
java × 1
url × 1