Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When implementing rest api methods in Salesforce, I often have to write code like this:

@HttpPost global static String CreateLead(
    String LastName, String Company, String Email, String Country,
    String State,String FirstName, String City, String Street, String Phone, String PostalCode)
            system.debug('###### Attempting to create new lead');
            Lead l = new Lead();
            l.LastName = LastName;
            l.Email = Email;
            l.Country = Country;
            l.State = State;
            l.FirstName = FirstName;
            l.City = City;
            l.Street = Street;
            l.Phone = Phone;
            l.PostalCode = PostalCode;
            l.Company = Company;

            system.debug('######Attempting to insert lead');
            insert l;

            return l.Id;

This is a little inefficient in that I have to specify each parameter. And in some cases I have to pass more parameters than possible for certain objects (36 parameter max). Is there a way to do something like...

@HttpPost global static String CreateLead(
        Lead MyLead)
//do stuff 

And then from my external implementations just pass whatever JSON I want without throwing exceptions if parameters do not exactly match?

share|improve this question
up vote 4 down vote accepted

You can surely do that provided you have flexibility to marshall the incoming JSON

Lets take a simple JSON and see what happens

"MyLead": {
    "LastName": "TestAccount1",
    "Email": "",
    "Country": "India",
    "FirstName": "mohith"

Now let me draft the code for this as you wished and loved

 global class SampleRest{

 global static String CreateLead(Lead MyLead){
   insert MyLead;

Last bit is testing it up ,workbench REST Utility is God (Hate CURL )

enter image description here

share|improve this answer
The "MyLead:" was the answer! Thank you! – Darkenor Jul 15 '14 at 20:22
@Darkenor Thanks nps .Glad it helped you – Mohith Shrivastava Jul 15 '14 at 20:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.