0

New to writing test scripts. Looking for help in error in Unexpected token 'Lead' for my test code. I have a static field that pulls off time stamp to only pull data after a certain time. I am currently at 70% code coverage however the test class is erroring on "Class.NewLeads.doGet: line 8, column 1 Class.NewLeadTest.testMethod1: line 12, column 1"

@isTest
private class NewLeadTest
{
  static testMethod void testMethod1()
    {
RestRequest req = new RestRequest(); RestResponse res = new RestResponse();
req.requestURI = '/services/apexrest/NewLeads?time_stamp=07/10/2019+12:36+PM'; req.httpMethod = 'GET';
RestContext.request = req; RestContext.response = res;
List returnList = NewLeads.doGet() ;
} @isTest static void NewLeadPost() {

   RestRequest req = new RestRequest();
   RestResponse res = new RestResponse();    
   req.requestURI = '/services/apexrest/NewLeads?time_stamp=07/10/2019+12:36+PM';
   req.httpMethod = 'POST';     
   RestContext.request = req;
   RestContext.response = res;

   List<Lead> lds = new List<Lead>(); 
   Lead leadToCreate = new Lead();
   leadtoCreate.FirstName = 'Ray';
   leadToCreate.LastName = 'Lewis';
   leadToCreate.Middlename = 'Andy';
   leadtoCreate.Phone = '678-782-1111';
   leadtoCreate.Street = '234 State Route Clarkston';
   leadtoCreate.City = 'Dawson';
   leadtoCreate.StateCode = 'GA';
   leadtoCreate.PostalCode = '30034';
   leadtoCreate.Email = 'Ray.lewis@ymail.com';
   lds.add(leadToCreate);

   NewLeads.doPost(lds);

} }

@RestResource (urlMapping='/NewLeads') global with sharing class NewLeads { @HttpGet global static Lead[] doGet() { RestRequest req = RestContext.request; String time_stamp = req.params.get('time_stamp'); Datetime dt = DateTime.parse(time_stamp); Lead[] Leads = [Select Firstname, Lastname, Middlename, Suffix, Phone, Secondary_phone__c, Street, City, Statecode, Postalcode, Country, Region__c, Date_of_birth__c, Age__c, Email

from Lead WHERE CreatedDate > :dt ]; return Leads; } @HttpPost global static String doPost(Lead[] Leads) { upsert leads; return Leads[0].LastName; } }

  • P.S. Your doPost method could be written as: @HttpPost global static String doPost(Lead[] Leads) { upsert leads; return Leads[0].LastName; } This would help increase code coverage with less complexity. – sfdcfox Jul 31 at 15:51
  • 1
    P.P.S. Consider using a ISO 8601-formatted time stamp (YYYY-MM-DD HH:MM:SS) in GMT, and use DateTime.valueOfGmt. This avoids time zone errors and locale settings that you may get using DateTime.parse. – sfdcfox Jul 31 at 15:56
  • Thank you I was able to update the HttpPost Code. – Khylin Edwards Jul 31 at 16:03
  • Hi I am almost at code coverage for this class. Is there anything else you see that can help me clear the code? I have update the code with my latest changes. – Khylin Edwards Jul 31 at 19:25
  • Your code is kind of screwed up (copy-paste error?). If you called the two methods, you should get 100% coverage. – sfdcfox Jul 31 at 19:45
1

You have a comma between the last field in the SELECT clause and the FROM clause

ce,

      from Lead 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.