You need to sign in to do that
Don't have an account?
Erik Rodgers
Would someone please explain the structure of this syntax
Below is an excerpt from some code we use to make a web service call to a Twilio API in our production environment. It appears very straight forward, but I am new to Force.com Apex syntax, so I'm trying to understand things that just don't make sense to me. So, how does the Map object accept two (2) String parameters for the name/value pair, but the code in the braces represents three (3) Strings - To, From, and Body. 2 is not equal to 3, so I am confused. I know this is a dumb newbie question, but I have to know.
Map<String,String> params = new Map<String,String> {
'To' => toNumber,
'From' => String.isBlank(twilioCfg.From_Phone_Number__c) ? '+15005550006' : twilioCfg.From_Phone_Number__c,
'Body' => smsBody
};
Thanks!
Erik
Map<String,String> params = new Map<String,String> {
'To' => toNumber,
'From' => String.isBlank(twilioCfg.From_Phone_Number__c) ? '+15005550006' : twilioCfg.From_Phone_Number__c,
'Body' => smsBody
};
Thanks!
Erik
Map is not taking three parameters but actually it is containing three different key value pair. Once you will print this map map count will be 3
At 0 Place 'To' String,String
At 1 Place <String,String>
at 2 Place <String,String>
Makes sense?
Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant
P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
All Answers
Everything is in two string. 'From' will get single value becasue it is taking value using ternary operator (?) where only one value will be assigned in 'From'.
Makes sense ?
Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant
P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
Himanshu, I still do not understand. Here is what I am seeing:
- Map takes two (2) inputs
- Assignment syntax assigns three parameters: (1) To (2) From (3) Body.
I understand what the ternary operator is doing for the From parameter, but there are still three parameters. What gives??Map is not taking three parameters but actually it is containing three different key value pair. Once you will print this map map count will be 3
At 0 Place 'To' String,String
At 1 Place <String,String>
at 2 Place <String,String>
Makes sense?
Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant
P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
First of all, Please accept my appologies that I tried to explain ternary operator to you. I did that because I thought that perhaps you missed that mistakenly. :) and I am again feel sorry to make you confused by my answer. I added that in index format only to explain no. of items map will hold. values never get as indexed they are there only in key,value pair as it happend in other language.
Thanks,
Himanshu