You need to sign in to do that
Don't have an account?
agarcia
Accept external data via URL parameters
I have a vendor that wants to send new records to our existing RestResource via URL parameters (...abc.com?Name=Sample&Phone=8135551212). How can I accept this? I have been looking into JSON.deserializeuntyped(req.requestbody.tostring() but I just cant get anything to work.
As a side note, my RestResource is exposed publicly via site.com with permissions to POST only.
Here is a sample of what my code currently looks like.
@RestResource(urlMapping='/abc/*')
global with sharing class sample {
@HttpPost
global static Map <String,String> createrecord (String Name,
String Phone) {
Map <String, String> s = new Map <String, String>();
record r = new record(
Name__c = Name,
Phone__c = Phone);
Database.SaveResult db = Database.insert(r, false);
if(db.isSuccess()){
s.put('isSuccess','True');
s.put('status','Success');
s.put ('RecordId',r.Id);
}
else{
s.put('isSuccess','False');
s.put('status','failure');
s.put('message','Error');
s.put('errorCode','Not Found');
List <Database.Error> errors = db.getErrors();
for(Database.Error error : errors){
s.put('error', error.getMessage());
}
}
return s;
}
}
As a side note, my RestResource is exposed publicly via site.com with permissions to POST only.
Here is a sample of what my code currently looks like.
@RestResource(urlMapping='/abc/*')
global with sharing class sample {
@HttpPost
global static Map <String,String> createrecord (String Name,
String Phone) {
Map <String, String> s = new Map <String, String>();
record r = new record(
Name__c = Name,
Phone__c = Phone);
Database.SaveResult db = Database.insert(r, false);
if(db.isSuccess()){
s.put('isSuccess','True');
s.put('status','Success');
s.put ('RecordId',r.Id);
}
else{
s.put('isSuccess','False');
s.put('status','failure');
s.put('message','Error');
s.put('errorCode','Not Found');
List <Database.Error> errors = db.getErrors();
for(Database.Error error : errors){
s.put('error', error.getMessage());
}
}
return s;
}
}
while calling this
@HttpPost method you need to set body and heders of this method ..body should be in json format
may I know from where you are calling this @HttpPost method..
so please can you tell me from where are u calling this method or paste code here so I can help to
by changing your url it should work
for eg:-
abc.com/Sample/8135551212
I originally posted this on success.salesforce and the suggestion given was to add
Map <String, String> mapofparams = RestContext.request.params;
String name =mapofparams.get('name');
String Phone=mapofparams.get('Phone');
But in doing that I get the Error: Compile Error: Variables cannot be marked as Http*