+ Start a Discussion
Nihon TaisaiNihon Taisai 

External ID for @HttpPost in Apex REST

When we post a Box record we also send Id from another record (callout side) in External Id for Box record. How can we write this request in HttpPost code? Or we don't need it in HttpPost?

My code:
@HttpPost
    global static Box__c postBox(String title){
        RestRequest req = RestContext.request;
                                                                
        Box__c b = new Box__c(
            Title__c = title,
            );
        insert b;
        return b;
    }

 
Best Answer chosen by Nihon Taisai
Raj VakatiRaj Vakati
Like below .. Return ID as a String .. 
 
@HttpPost
    global static String postBox(String title){
        RestRequest req = RestContext.request;
                                                                
        Box__c b = new Box__c(
            Title__c = title,
            );
        insert b;
        return b.Id;
    }

 

All Answers

Raj VakatiRaj Vakati
Like below .. Return ID as a String .. 
 
@HttpPost
    global static String postBox(String title){
        RestRequest req = RestContext.request;
                                                                
        Box__c b = new Box__c(
            Title__c = title,
            );
        insert b;
        return b.Id;
    }

 
This was selected as the best answer
Raj VakatiRaj Vakati
External System will get Id as Response ..