Apex class -
@RestResource(urlMapping='/account')
global class createAccount
{
@HttpPost
global static void createAcc()
{
//-- Data coming from request
String strFirstName = RestContext.request.params.get('First_Name');
String strLastName = RestContext.request.params.get('Last_Name');
String strPhone = RestContext.request.params.get('Phone');
String strEmail = RestContext.request.params.get('Email');
String strTitle = RestContext.request.params.get('Title');
system.debug('RestContext.request.params: '+RestContext.request.params);
system.debug('First_Name: '+strFirstName);
system.debug('Last_Name: '+strLastName);
system.debug('Phone: '+strPhone);
system.debug('Email: '+strEmail);
system.debug('Title: '+strTitle);
}
}
When I check the debug log, the last debug statement shows null value.
12:17:31.033 (33840000)|USER_DEBUG|[21]|DEBUG|RestContext.request.params: {Email=abc@gmail.com, First_Name=FirstName, Last_Name=LastName, Phone=+1234567890, Title=Mr}
12:17:31.033 (33886000)|USER_DEBUG|[23]|DEBUG|First_Name: FirstName
12:17:31.033 (33929000)|USER_DEBUG|[24]|DEBUG|Last_Name: LastName
12:17:31.033 (33963000)|USER_DEBUG|[25]|DEBUG|Phone: +1234567890
12:17:31.033 (33998000)|USER_DEBUG|[26]|DEBUG|Email: abc@gmail.com
12:17:31.034 (34035000)|USER_DEBUG|[27]|DEBUG|Title: null
Attribution to: Swati
Possible Suggestion/Solution #1
As a starting point, I recreated you class and request. Using the dev console the output was properly displayed. Check to ensure your URL you are creating does not include and special characters before Title. Your paste also seems to strip off the Title=Mr in the URL. Again, recreating and calling from the dev console works just fine
Attribution to: Eric
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/34668