Activity
Mon
Wed
Fri
Sun
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
What is this?
Less
More

Memberships

Integration Mastery Cohort

36 members • Free

Apex Mastery Cohort

18 members • Free

LWC Mastery Cohort

25 members • Free

8 contributions to Integration Mastery Cohort
US Week 6 - Webhooks
A surprisingly simple solution to integrations. We start in about half an hour. See you there!
0 likes • 4d
Here's the video! https://share.butter.us/recap/9442421f-425f-4d73-a21d-729691c73442
US Week #5 - Authentication... in an hour!
This is gonna be a weird one. Let's push through together.
1 like • 10d
Here's the video from today's class: https://share.butter.us/recap/9e2f4736-b176-4836-b0cb-63e07f809fc6
0 likes • 18d
Here's today's video: https://share.butter.us/recap/fbd74bfa-3a4a-4302-8672-df90abcc210d
US Week #3 in about an hour. See you soon!
Callouts from triggers... aka, async stuff in Salesforce.
0 likes • 24d
Here's the code I was using during class today. And here's the link to the Butter class for the video: https://share.butter.us/recap/bd60bc86-167a-46c5-ada9-c4050bf96256
Map vs. Generic Object
@Alon Waisman, I tried creating generic objects for the payment link from last week but the nested objects are not populated. Below is my code and attached is the screen shot of the debug log. What am I doing wrong? HttpRequest request = new HttpRequest(); request.setMethod('GET'); request.setEndPoint('https://735ef563-176d-431c-85ce-2cc07056ef03.mock.pstmn.io/payments/link'); Http http = new Http(); HttpResponse response = http.send(request); String responseBody = response.getBody(); //Map<String, Object> responseMap = (Map<String, Object>) JSON.deserializeUntyped(responseBody); //Map<String, Object> Payer = (Map<String, Object>) responseMap.get('payer'); //Map<String, Object> thisTransaction = (Map<String, Object>) responseMap.get('transaction'); public class MyPayment { String paymentId; Integer timestamp; Decimal amount; MyBankAccount bankAccount; MyAddress address; } public class MyBankAccount { String bankName; Integer routingNumber; Integer accountNumber; } public class MyAddress { String street; String city; } MyPayment myPay = (MyPayment) JSON.deserialize(responseBody, MyPayment.class); //MyTransaction mycurrentTransaction = (MyTransaction) myPayment.get('transaction'); System.debug(myPay); System.debug(myPay.bankAccount); System.debug(myPay.address); //System.debug(responseMap.get('currency')); //System.debug(payer.get('link')); //System.debug(thisTransaction.get('transactionStatus'));
Map vs. Generic Object
2 likes • Nov 5
The problem is that your classes (aka templates) don't properly represent the data in the JSON. You have three classes - MyPayment, MyBankAccount, and MyAddress... I'll refer to them as a payment, bank account, and address. Your MyPayment class looks like this: public class MyPayment { String paymentId; Integer timestamp; Decimal amount; MyBankAccount bankAccount; MyAddress address; } You can see that you've described the payment object as having a property for the bank account, but if you look at the JSON you're deserializing into this class, you'll see that the bank account data is not directly linked to the payment. Instead, it's inside of another object referred to as the payee. So, if you took the entire JSON data and assigned it to variable called payment, you would reference the bank account info as payment.payee.bankAccount... but your coding is TRYING to reference it as payment.bankAccount. In simple terms, you skipped the objects in the middle and tried to stick deeply nested objects into the first layer of data which, of course, you can't do. The templates you're creating need to be exact. The deserialization process might see a key that matches a key you've defined in one of your classes, but if that key isn't in the class where it expects it to be, it won't use it. The reason for this becomes obvious when you realize that you can use the same key (aka variable name) in multiple classes... so if it just added data from the JSON to any matching variable name in your collection of classes, everything would blow up when duplicate variable names are used across classes. I know I went on for a bit there, but I hope it explained the issue. Let me know if you still have any questions.
2 likes • Nov 5
@Kharaam Sharifpour Ah, this is a fun issue I’ve been dealing with myself this week. What a pain! There’s no simple solution - the bottom line is that you can’t use certain words as variable names. So you’re stuck having to use different names. No way around that. And since that would make the deserialization process fail for that key the easiest solution is to change the JSON before you deserialize it. This is technically an imperfect solution, but in practice, it probably won’t cause any problems. Do something like this: jsonResponse = jsonResponse.replaceAll(‘“transaction”:’, ‘“transactionKey”:’).replaceAll(‘“otherReservedWord”:’, ‘“otherSafeKey”:’); This way, you’re translating the keys they give you into something else you prefer to use and which Apex allows.
1-8 of 8
Alon Waisman
2
5points to level up
@alon-waisman-8907
.

Active 2d ago
Joined Oct 27, 2025
Powered by