0
@RestResource(urlMapping='/Account/*')
global with sharing class MyRestResource {

    @HttpDelete
    global static void doDelete() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        Account account = [SELECT Id FROM Account WHERE Id = :accountId];
        delete account;
    }

    @HttpGet
    global static Account doGet() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        Account result = [SELECT Id, Name, Phone, Website FROM Account WHERE Id = :accountId];
        return result;
    }

  @HttpPost
    global static String doPost(String name,
        String phone, String website) {
        Account account = new Account();
        account.Name = name;
        account.phone = phone;
        account.website = website;
        insert account;
        return account.Id;
    }
}

Host Name https://na34.salesforce.com

uri (which is needed to be shared with cross functional team) https://na34.salesforce.com/services/apexrest/Account

I am getting error as " The content you are trying to view cannot be xml

1 Answer 1

1

You don't say where the error is being reported, but assuming it is from an external client it looks like your MyRestResource is returning XML but the client expects JSON.

You can ensure a JSON response by getting the client-side code to set an "Accept" header of "application/json" or to append ".json" to the URL.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .