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
Elavarasan BalasubramaniyanElavarasan Balasubramaniyan 

Regarding Apex Class Execution and also Write Test Class

@HttpPost
global static String doPost() {
       RestRequest req = RestContext.request;
       RestResponse res = Restcontext.response;

       Blob body = req.requestBody; System.debug('Test:' + body.toString());
       
       
UpdateProfile profiles = (UpdateProfile)System.JSON.deserialize(body.toString(),UpdateProfile.class); System.debug('Parsed Input:' + profiles);
 
if (profiles.UserId == '' || profiles.UserId == Null)  profiles.UserId = UserInfo.getUserId();
return updateProfileDetails(profiles); }

global static String updateProfileDetails(UpdateProfile profiles)
{
try { list < User > users = [Select id, Title, FirstName, LastName, Email, Username, Country, MobilePhone, Fax, Phone, ContactID, AccountID, PG_SecretAnswer__c, PG_SecretQuestion__c, PG_SecretAnswerSalt__c, JE_Password__c, PG_TCAgreed__c, IsActive from User where Id =: profiles.UserID];

if (!users.isEmpty()) {}

else { throw new CustomException(PG_Utils.getException(USER_ERROR, GENERIC_ERROR_TYPE, CustomException__c.getValues('PC0001').Error_Description__c)); //user Not Found Given with another Id means Account Id } }

catch (Exception e)
{ return e.getMessage(); //user Id is like erty or alphabets }

return null; // when?????? }
When this Class Function Return Null Statement,How to write a test Class for Failing Input for Returning Null Statement???
This Class Indicates In PostMan what are the request Body which is Given that is Updated with the particular user with the help of userId, If user Id is Not Given, By Default it Take with the Help of Statement userinfo.getUserId, when this Class Function Return Null Statement,How to Write a test class for Failing Input for Returning Null Statement,Please Anyone Guide Me?


 
pconpcon
You test it like you would any other class [1].  You would just provide the incorrect information to get into your catch.

[1] http://blog.jeffdouglas.com/2012/03/21/writing-unit-tests-for-v24-apex-rest-services/