salesforce中返回Null的Rest Api的内容类型
我正在尝试调用这个RESTAPI方法salesforce中返回Null的Rest Api的内容类型,salesforce,apex-code,visualforce,Salesforce,Apex Code,Visualforce,我正在尝试调用这个RESTAPI方法 @HttpGet global static String retrievingNotificationSettings(){ RestRequest req=RestContext.request; RestResponse res=RestContext.response; String accountId = req.requestURI.substring(req.requestURI.lastIndex
@HttpGet
global static String retrievingNotificationSettings(){
RestRequest req=RestContext.request;
RestResponse res=RestContext.response;
String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
if(req.headers.get('Content-Type').equals('application/xml'))
{
Map<String, SObjectField> fields = Notification_Settings__c.SObjectType.getDescribe().fields.getMap();
Schema.sObjectField T ;
Notification_Settings__c ss;
return 'hello World';
}
if(req.headers.get('Content-Type').equals('application/json'))
return System.JSON.serialize(note);
return null;
我得到的回应是
HTTP/1.1 500 Internal Server Error
Date:
Fri, 25 Jan 2013 16:30:21 GMT
Content-Length:
203
Connection:
close
Content-Type:
application/json; charset=UTF-8
Server:
[
{
"message": "System.NullPointerException: Attempt to de-reference a null object\n\nClass.NotificationRestService.retrievingNotificationSettings: line 34, column 1",
"errorCode": "APEX_ERROR"
}
]
我得到的错误是
if(req.headers.get('Content-Type').equals('application/xml'))
我不明白为什么我在头文件中将值内容类型作为application/json传递时会出现这个错误??请告诉我哪里出错您能System.debug(req.headers)
查看它是否正确通过吗
要逐字回答空指针问题,请使用=
而不是equals
:
if(req.headers.get('Content-Type') == 'application/xml')
但这并不能解决真正的根本问题
您可能想尝试使用不同的头(愚蠢,我知道),或者决定添加一个GET参数,比如&mode=json
if(req.headers.get('Content-Type') == 'application/xml')