0

Can we use a map? And how to do that? Too many fields here already and we can add more in future.

@HttpPost
global static Ticket__c postT(String title, String whattime, String whatdate, String whatplace, String externalId, String manager, String phone, String email){

    Ticket__c thisT = new Ticket__c(
        Title__c = title,
        Time__c = whattime,
        Date__c = whatdate,
        Place__c = whatplace,
        Manager__c = manager,
        Email__c = email,
        Phone__c = phone,
        ExtID__c = externalId
        );
    insert thisT;
    return thisT;
}
3

you can create create WrapperClass for Ticket, create JSON object and send it as param of request

@HttpPost
global static Ticket__c postT(TicketWrapper wrapper){
    Ticket__c thisT = wrapper.converttoSobject();
    insert thisT;
    return thisT;
}


global class TicketWrapper{
    public String title {get; set;}
    public String whattime {get; set;}
    public String whatdate {get; set;}
    public String whatplace {get; set;}
    public String externalId {get; set;}
    public String manager {get; set;}
    public String phone {get; set;}
    public String email {get; set;}

    public Ticket__c converttoSobject(){
        return new Ticket__c(
            Title__c = title,
            Time__c = whattime,
            Date__c = whatdate,
            Place__c = whatplace,
            Manager__c = manager,
            Email__c = email,
            Phone__c = phone,
            ExtID__c = externalId
            );
    }
}

example of such POST body:

{
    "wrapper" : {
        "title" : "testservice",
        "whattime" : "testservice",
        "whatdate" : "testservice",
        "whatplace" : "testservice",
        "externalId" : "testservice",
        "manager" : "testservice",
        "phone" : "testservice",
        "email" : "testservice"
    }
}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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