I want to write test class for following Rest API, But  i am new in salesforce please help me..... @RestResource(urlMapping='/registerEvent/*') global class RegisterEventApi {     @HttpPost     global static void createCampMem() {         try{             RestRequest request = RestContext.request;             if(String.isNotBlank(request.requestBody.toString())){                 Map&lt;string,Object&gt; reqMap = (Map&lt;string,Object&gt;)JSON.deserializeUntyped(request.requestBody.toString());                 string EventId = (string)reqMap.get('EventId');                 string eventSlotId = (string)reqMap.get('eventSlotId');                 string accountId = (string)reqMap.get('accountId');                                if(String.isBlank(EventId)){                     string jsonstr = '{&quot;success&quot;:'+false+',&quot;message&quot;:&quot;Provide jamiyaEventId&quot;}';                     RestContext.response.addHeader('Content-Type','application/json');                     RestContext.response.responseBody = Blob.valueOf(jsonstr);                     RestContext.response.statusCode = 403;                     return;                 }  if(String.isBlank(eventSlotId)){                 string jsonstr = '{&quot;success&quot;:'+false+',&quot;message&quot;:&quot;Provide eventSlotId&quot;}';                 RestContext.response.addHeader('Content-Type','application/json');                 RestContext.response.responseBody = Blob.valueOf(jsonstr);                 RestContext.response.statusCode = 403;                 return;             }             if(String.isBlank(accountId)){                 string jsonstr = '{&quot;success&quot;:'+false+',&quot;message&quot;:&quot;Provide accountId&quot;}';                 RestContext.response.addHeader('Content-Type','application/json');                 RestContext.response.responseBody = Blob.valueOf(jsonstr);                 RestContext.response.statusCode = 403;                 return;             }             Id contactId = [SELECT Id FROM contact WHERE accountId =:accountId].Id;             List&lt;Event_Registration__c&gt; existingReg = [SELECT Id FROM Event_Registration__c WHERE Contact__c=:contactId                                                     AND Event_Slot__c=:eventSlotId];             if(existingReg.isEmpty()){                 Event_Registration__c eventReg = new Event_Registration__c();                 eventReg.Event__c = EventId;                 eventReg.Event_Slot__c =eventSlotId;                 eventReg.Contact__c = contactId;                 eventReg.Status__c ='Scheduled';                 insert eventReg;                 RestContext.response.addHeader('Content-Type','application/json');                 RestContext.response.responseBody=Blob.valueOf('&quot;success&quot;:'+true+',&quot;Id&quot;:' +eventReg.Id);                 RestContext.response.statusCode = 200;                 return;             }             else{                 RestContext.response.addHeader('Content-Type','application/json');                 RestContext.response.responseBody = Blob.valueOf('{&quot;success&quot;:'+false+',&quot;message&quot;:&quot;Record Already Exists&quot;}');                 RestContext.response.statusCode = 409;                 return;             }         }     }     catch(Exception e){         RestContext.response.responseBody=Blob.valueOf('Error: ' +e.getMessage());     } }        }
I was writing test classes for my apex Rest Service that I had built for an Ipad app.  I noted some very interesting things while experimenting. Before doing anything, I just did a google search and found an interesting blog post by Jeff.    @RestResource(urlMapping='/v.9/member/*/results/*')  global with sharing class MemberRestSvc {  @HttpGet  global static ReturnClass doGet() {  String[] uriKeys = RestContext.request.requestURI.split('/'); // get the member name from the uri String memberName = uriKeys.get(uriKeys.size()-3);  // do awesome programming stuff here &amp; catch any exceptions try {    List&lt;Contact&gt; contacts = [Select Id From Contact where member_name__c = :memberName];   return new ReturnClass('true', 'Query executed successfully.', contacts);  } catch (Exception e) {   return new ReturnClass('false', e.getMessage(), null); }   }   global class ReturnClass {  global String success; global String message; global List&lt;Contact&gt; records;    global ReturnClass(String success, String message, List&lt;Contact&gt; records) {   this.success = success;   this.message = message;   this.records = records;  }  }  }   And here is the test class  @isTest private class Test_MemberRestSvc {  static { // setup test data   }  static testMethod void testDoGet() {  RestRequest req = new RestRequest();  RestResponse res = new RestResponse();  req.requestURI = 'https://cs9.salesforce.com/services/apexrest/v.9/member/me/results/today';   req.httpMethod = 'GET'; RestContext.request = req; RestContext.response = res;  MemberRestSvc.ReturnClass results = MemberRestSvc.doGet();  System.assertEquals('true', results.success); System.assertEquals(10, results.records.size()); System.assertEquals('Query executed successfully.', results.message);  }  }   I just commented a few lines and ran and it. I still achieved enough test coverage so my question is why do I need to simply instantiate the Rest request and response objects since I am directly calling the class?    @isTest   private class Test_MemberRestSvc {    static {     // setup test data     }  static testMethod void testDoGet() {  /*RestRequest req = new RestRequest();  RestResponse res = new RestResponse();  req.requestURI =    'https://cs9.salesforce.com/services/apexrest/v.9/member/me/results/today';   req.httpMethod = 'GET'; RestContext.request = req; RestContext.response = res; */Commented the code meant for REST apex intialization and merely calling the method!!  MemberRestSvc.ReturnClass results = MemberRestSvc.doGet();  System.assertEquals('true', results.success); System.assertEquals(10, results.records.size()); System.assertEquals('Query executed successfully.', results.message);  }  }   Can someone explain this behavior? Also what are the best practices for writing Test classes for apex Rest services?
Why do PBX systems use -48 V? "Parsing filters unsupported" error during extraction of RAR file I have received an .rar which I wish to unpack as it contains something rather important to me that I need to really have now. However even though I can view the contents of the .rar archive in the Archive Manager, I am unable to extract it due to this error:    The archive should contain two folders within it, each though contain at least 10 audio files as well as a PDF file each (I don't know what the contents exactly should be except for there should be audio files in there, and the content I have described is what I can see from the Archive Manager's view). So the only thing I am left with except the error is one of the folders and one of the audio files, but it says it has 0 bytes in it.  So how exactly do I fix this problem? I am running Ubuntu GNOME 16.04.1 with GNOME 3.20.  Information Update:  In reply to a comment requesting the output from the dpkg -l unrar unrar-free command:  Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) ||/ Name           Version      Architecture Description +++-==============-============-============-================================= un  unrar          &lt;none&gt;       &lt;none&gt;       (no description available) dpkg-query: no packages found matching unrar-free Combo box in Java - nullpointer Unicode identifiers in Python? Index notation Lorentz transfromation matrix How to run a complete GUI as root? How can I get Gnome3 to remember my session? Encode URL in JavaScript? How do you safely encode a URL using JavaScript such that it can be put into a GET string?  var myUrl = "http://example.com/index.html?param=1&amp;anotherParam=2"; var myOtherUrl = "http://example.com/index.html?url=" + myUrl;   I assume that you need to encode the myUrl variable on that second line? Print lines between (and including) two patterns I am working on an app that allows customers to upload images, video, (even gif) into my app. Once the case is processed on my app, I want to place those media files into Salesforce. I have a case record that I would this attached to.   I see multiple records can be added in Rest , and that files can be added to notes and attachments. Can I upload multiple notes and attachments in a single rest call? I'm working on an exercise from functional analysis.  Let $E$ be a vector space and $\|\cdot\|_1$ and $\|\cdot\|_2$ be two complete norms on $E$. Now suppose that $E$ satisfies the following property:  $\bullet$ if $(x_n)$ is a sequence in $E$ and $x,y\in E$ such that $\|x_n-x\|_1\to 0$ and $\|x_n-y\|_2\to 0$, then $x=y$.  Now we want to show that the norms $\|\cdot\|_1$ and $\|\cdot\|_2$ are equivalent.  My idea is as follows: If for any $n&gt;0$, there is an element $x_n\in E$ such that $\|x_n\|_1&gt;n\|x_n\|_2$. Then consider $(\frac{x_n}{\|x_n\|_1})_{n\geq 1}$. Clearly, $(\frac{x_n}{\|x_n\|_1})_{n\geq 1}$ converges to $0$. However, I cann't get a contradicition from this. Maybe my idea is wrong.   In fact, I even don't konw how to show that a Cauchy sequence in norm $\|\cdot\|_1$ is also a Cauchy sequence in norm $\|\cdot\|_2$.   Anyone can give me some hints or a counter example? Thank you very much. After installing Ubuntu Studio 12.04, I have found that it uses a low latency kernel.   I searched for an explanation and how to change back it to a real-time or generic one. However, it looks like this part of Linux hasn't been covered to explain the details.   Q: Why choose a low latency kernel over a generic or real-time one?  PS: I have already read the answers from  question and  post. I want something similar to "preview" in macs.  For example: I want an image editor that ONLY does simple adjustments like increase/decrease contrast, saturation, exposure, color tinting.... rotate, flip vertically, flip horizontally, make black and white, change size or format, crop.  THATS IT.  I know gimp can do all those things but its a bit overkill.  I just want to right click an image, open it with this magical program i just described, do a few quick adjustments, and then save and exit.  Nothing really fancy.  Anyone know of anything like this?  Btw I am using ubuntu 12.04 :) It rocks and I am glad I switched from mac, i just need to replace this one piece of software. I'm trying to set an RSA key as an environment variable which, as a text file, contains newline characters.  Whenever I attempt to read from the file and pass it into an environment variable, it will just stop at the newline character on the first line. How can I prevent this? Mixed content on many SE sites Many SE sites (like math.SE) have a problem with mixed content, which causes display bugs in recent browsers. This is particularly evident with math.SE (because of the huge use of MathJax) and with chat sections.  Will this be fixed?  How to reproduce  Visit  or   What happens  Mixed content is blocked, output is missing pieces of code (MathJax):    This picture also includes my main Firefox addons (top right), it relevant. It shows missing styles:    The white on the left is my tab list. Reclassifying only part of raster keeping rest unchanged? I'm trying to reclassify only a certain part of a raster...not the entire raster.  Here's the problem.  I have a LULC raster of the entire US.  There are some issues with the raster that I want to fix, namely some cells that should be water are classified as wetlands.  These are mainly off the coast, not inland.  However, some cells that are classified as wetlands should really be wetlands (mainly inland) and I don't want these to change.  I plan on using a ZIP Code boundary file to determine which cells are considered "off the coast" and which ones are not.  I have access to ArcGIS 10.1 and R with the appropriate raster packages I need so a solution in either software would be fine.  Can anyone help me figure this out? How can I find my hardware details? Is there any built-in software or terminal method allowing me to view the hardware profiles on my system? Windows equivalent of such a feature would be Device Manager. How do I efficiently filter computed values within a Python list comprehension? The Python list comprehension syntax makes it easy to filter values within a comprehension.  For example:  result = [x**2 for x in mylist if type(x) is int]   Will return a list of the squares of integers in mylist.  However, what if the test involves some (costly) computation and you want to filter on the result?  One option is:  result = [expensive(x) for x in mylist if expensive(x)]   This will result in a list of non-"false" expensive(x) values, however expensive() is called twice for each x.  Is there a comprehension syntax that allows you to do this test while only calling expensive once per x? How is offside determined in football? The offside rule on the pitch is often unclear and called suddenly. How do I know if a player is offside? I know base 2 and base 10 , MB and MiB, but i'm not understanding the byte counts shown for a directory, by du and by windows explorer The du command shows 43G in use. I'm not sure whether that's base 2 in the sense of 2^30 or if it's base 10, in the sense of 10^9.  But anyhow -   Running this du command from cygwin, to see the size of the windows directory (done from an administrative command prompt - since it seemed to have some issues reading some directories otherwise)  user@comp ~ $ du -sh /cygdrive/c/windows 43G     /cygdrive/c/windows   Windows Explorer  which I understand shows it in 'base 2', (a larger unit for KB,MB,GB than base 10 KiB, MiB e.t.c.), and hence a lower quantity of that larger unit is required to give the same result.    Windows explorer shows      46.6GB  , over 50 billion bytes.    (according to windows explorer)  or  46.8GB  , over 50 billion bytes. (according to windows explorer)  So, du aside.  Even if I multiply the larger figure, 46.8GB  by 1.048576 then I get 49.0733568 that's not over 50 billion. So that's part A of the question,  but then also, part B of the question, why is the du figure so low.