• parikshit sarkar
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies
I'm using Workbench to test an Apex Rest POST API that I'm writing.  I want to pass paramters in the request object (not in the URL).  
So..., I don't understand what to put the in the request body field on the Workbench REST Explorer.

I was thinking that all I needed was...
{
"Parm1" : "Value1" , 
"Parm2" : "Value2"
}

But when I do that - I don't see those values in the body of the request, or in the params.

My apex code is:
@HttpPost
    global static string returnClientInfo() {
    	RestRequest		request 	= RestContext.request;
    	RestResponse	response	= RestContext.response;
    	
    	string	pParam1		= request.params.get(Param1');
    	string	pParam2		= request.params.get('Param2');
    	
    	response.addHeader('Content-Type','applicatin/json');
    	 	
    	return 'returnClientInfo finished.' + pParam1 + ' ' + pParam2 + ' request=' + request + ' request.params=' + request.params;
    }

I'm getting null for both params, and {} for the response.params.

Thanks
hi
i am new to salesforce platform.
Install a simple Apex class, write unit tests that achieve 100% code coverage for the class, and run your Apex tests.The Apex class to test is called 'VerifyDate', and the code is available here. Copy and paste this class into your Developer Edition via the Developer Console.
'VerifyDate' is a class which tests if a date is within a proper range, and if not will return a date that occurs at the end of the month within the range.
The unit tests must be in a separate test class called 'TestVerifyDate'.
The unit tests must cover scenarios for all lines of code included in the Apex class, resulting in 100% code coverage.
Run your test class at least once (via the Developer Console) before attempting to verify this challenge.

In the above challege i am not able to write a 'TestVerifyDate' class. I dont unsertstand how to write it for a date.
plz help..
My Trigger is as following:-

trigger RestrictContactByName on Contact (before insert, before update)
{ //check contacts prior to insert or update for invalid data
For (Contact c : Trigger.New)
{
if(c.LastName == 'INVALIDNAME')
{ //invalidname is invalid
c.AddError('The Last Name "'+c.LastName+'" is not allowed for DML');
}
}
}

--------------------------------------------------
And my Test class as follows:-
@isTest
private class TestRestrictContactByName
{
    @isTest static void TestContact()
    {

        Contact con=new Contact(FirstName='Arjun', LastName='Mahi');
        if(con.LastName=='INVALIDNAME')
        {
             con.AddError('The Last Name "'+con.LastName+'" is not allowed for DML');
            
        }else{insert con;}  
 
        Contact conn=new Contact(FirstName='Arjun', LastName='Kapur');
         if(conn.LastName=='INVALIDNAME')
        {
             conn.AddError('The Last Name "'+conn.LastName+'" is not allowed for DML');
            
        }else {update conn;}  
       
        Contact com=new Contact(FirstName='Rama', LastName='INVALIDNAME');
        
        if(com.LastName=='INVALIDNAME')
        {
             com.AddError('The Last Name "'+com.LastName+'" is not allowed for DML');
            
        }else {insert conn;}
    }
}


plz help me complete this Challenge :)
Thanx in Advance :)
 

Hi ,

        Can ypu please send the sample code for http post in apex