function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
trailhead solutions 10trailhead solutions 10 

http post to push Data of sObject Dynamically

Hello All

I have to write a Apex rest service for http post, in order to Push the Salesforce Records.

Currently, To Query the records, they are using get method and connected App.But, now needs to change to Post method and that should be dynamically for any sObject.

Here I wrote for one Object. But, Some Please let me know what should I build the Code, for all sObjects dynamically.

@RestResource(urlMapping='/v1/sss-api/*')
global class Common_Api_Service {
    final static String baseUrl=URL.getSalesforceBaseUrl().toExternalForm();
    
    
    @Httppost
    global static String getObjectDetailsByQuery(String sobjectname, String sQuery){
        
        String con = 'Select AccountId, Id, Alternative_Email_2__c, Email, FirstName, LastName, HomePhone, MailingAddress, MailingCity, MailingCountry, MailingGeocodeAccuracy, MailingLatitude, MailingLongitude, MailingPostalCode, MailingState, MailingStreet, MiddleName, MobilePhone, Name, OtherAddress, OtherCity, OtherCountry, OtherGeocodeAccuracy, OtherLatitude, OtherLongitude, OtherPersonPhoneID__c, OtherPhone, OtherPostalCode, OtherState, OtherStreet, PersonID_Email__c, PersonID_Phone__c, Phone, Region__c, Secondary_Email__c, Previous_Emails__c FROM Contact' ;
         List <sObject> slist  = Database.query(con);
        return con;

    }
}

Thanks
GSN