How to get the gender of a first name in Salesforce Apex

An automated gender recognition system can open up some great possibilities for your app or website, not to mention user demographics. Rather than set this up from scratch, how about something a little easier? We’ve got an API with your name on it. Let’s take a look at how to get it running.

Installation of our API is a piece of cake: simply unzip the client into your project location.

Once that’s done with, proceed by calling nameGetGender and entering the desired name and two-letter country code of origin.

SwagNameApi api = new SwagNameApi();SwagClient client = api.getClient();// Configure API key authorization: ApikeyApiKeyAuth Apikey = (ApiKeyAuth) client.getAuthentication('Apikey');Apikey.setApiKey('YOUR API KEY');Map<String, Object> params = new Map<String, Object>{'input' => SwagGetGenderRequest.getExample()};try {// cross your fingersSwagGetGenderResponse result = api.nameGetGender(params);System.debug(result);} catch (Swagger.ApiException e) {// ...handle your exceptions}

Done! Here is what an example response looks like for the German name Greta:

{
"Successful": true,
"Gender": "Male"
}
Image for post
Image for post

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store