Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7763823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:45:22+00:00 2026-06-01T14:45:22+00:00

I am developing a Rest Web service in salesforce.com platform. I wrote it and

  • 0

I am developing a Rest Web service in salesforce.com platform. I wrote it and it is working properly and giving accurate responses when I call it. The problem is how to test it

@RestResource(urlMapping='/feedpost/*')

    global class Feedpost9
    {
      @HttpPut
      global static User updateCase() {
         RestRequest req=RestContext.request;
         User user=[SELECT id from User where email=:req.headers.get('email') LIMIT 1];
         return user;          
    }

}

Now my task is to test this REST web service method updateCase. For testing a POST request method I have to set the parameters in method call but in case of PUT method – how do I set RestContext.request in the test class?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:45:24+00:00Added an answer on June 1, 2026 at 2:45 pm

    There are two issues you must contend with in your unit tests:

    • The need for a valid RestRequest
    • The lack of data in a test environment

    Here is basic technique to setting up the request object your method wants

    global class Feedpost9 {
    
        // your methods here...
    
        static testMethod void testRest() {
            // set up the request object
            System.RestContext.request = new RestRequest();
            RestContext.request.requestURI = '/feedpost/whatever';
            RestContext.request.addHeader('email', 'blahblah@some.org');
            // Invoke the method directly
            Feedpost9.updateCase();
        }
    }
    

    The other problem you’re likely to have is that in Salesforce v24 and above unit-tests, by default, do not have access to your data. That’s because unit tests run in a kind of sandbox that have none of your data, but do contain your metadata (RecordTypes, etc). So, there are two techniques for getting data to your tests:

    1. Use the @isTest(SeeAllData=true) annotation on your method. This will give the test method access to your data.
    2. Have your test method build/insert the test data, then run your tests against that data. When the testing ends, your test data will miraculously disappear from your database.

    I prefer to use the later method, but sometimes I cheat…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a REST-ful web service using RESTEasy deployed on Tomcat. I've configured an
I'm going to be developing a REST-ful Web Service for a new public website.
I'm currently developing a WCF REST Web Service that will be running on Microsoft
We're in the process of developing a WCF REST web service which just receives
i used Zend Rest Controller for developing a web service, and now i need
I'm developing a Rest web service with WCF. I have the following contract: namespace
I'm developing a REST service, so a request could be something like this: /Data/Main/Table=Customers/
I am working on developing a pair of libraries to work with a REST
I have written a REST web service with Jersey Server (that totally rocks !).
I am developing an app for android mobiles that communicates with a json/rest web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.