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
agarciaagarcia 

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;
    }
}
Prithviraj_ChavanPrithviraj_Chavan
Hello agarcia,
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
agarciaagarcia
That is my dilema.  The vendor sending these new records cannot send them with JSON.  They will be sedning the information in the URL  Example:  mysite.com/abc?Name=TestName&Phone=8135551212
 
Prithviraj_ChavanPrithviraj_Chavan
Hi,
by changing your url it should work
for eg:-
abc.com/Sample/8135551212
agarciaagarcia
changing the URL to contain / insteat of Parameter=sample&Parameter2=8135551212 does not work.  I need the format to be    mysite.com/abc?Name=TestName&Phone=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*