+ Start a Discussion
Raja.PRaja.P 

I need Some help in writing Test Class.... Urgent

Hii Friends

I am not familiar  at writing test clas i got arequirement
so please kindly  help me in writing this test class

this  is my class



global with sharing class EFAjaxRemotingFunctionsController
{
public EFAjaxRemotingFunctionsController(){}
public EFAjaxRemotingFunctionsController(ApexPages.StandardController controller){

    }

/* Object used to populate reference to user */
public EF_Request__c EFRequest
{
get;
set;
}

@RemoteAction
global static String getUserData(String recordId)
{
List<User> user = [select FirstName, LastName, Title, CompanyName from User where Id = : recordId];
// These methods are for serializing  Apex objects into JSON format available since Winter’12 release

String JSONString = JSON.serialize(user);
//Depends on your needs and way you want to format your result. Lets just hardcode the status value for now.
return '{"data":' +JSONString+', "error": "null", "status":"SUCCESS"}';
}
}
Thanks in Advance I am so kind of u
Best Answer chosen by Raja.P
Sri549Sri549
Hello Raja,
As per your Requirment i am giving you following code which may help you .

@IsTest
global class Test_EFAjaxRemotingFunctionsController
{
global static testmethod void EFAjaxRemotingFunctionsController()
{
         Profile p=[SELECT Id,Name FROM Profile WHERE Name=:'System Administrator'];
       
         User urs = new User();
         urs.FirstName= 'test';
         urs.LastName= 'test';
         urs.email = 'test@gmail.com';
         urs.Alias='abcd';
         urs.Username='testdone@test.com';
         urs.CommunityNickname='abcd';
         urs.isactive=true;
         urs.EmailEncodingKey='UTF-8';
         urs.timezonesidkey='America/Los_Angeles';
         urs.LocaleSidKey='en_US';
         urs.languagelocalekey='en_US';
         urs.ProfileId= p.id;
         insert urs;

Apexpages.Standardcontroller controller=new Apexpages.StandardController(urs);
EFAjaxRemotingFunctionsController ef =new EFAjaxRemotingFunctionsController(controller);
EFAjaxRemotingFunctionsController.getUserData(urs.Id);
   }
}

ping me if your are not so reaching your requirment

or else

Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You,
Srinivas
SFDC Certified Developer




All Answers

Sri549Sri549
Hello Raja,
As per your Requirment i am giving you following code which may help you .

@IsTest
global class Test_EFAjaxRemotingFunctionsController
{
global static testmethod void EFAjaxRemotingFunctionsController()
{
         Profile p=[SELECT Id,Name FROM Profile WHERE Name=:'System Administrator'];
       
         User urs = new User();
         urs.FirstName= 'test';
         urs.LastName= 'test';
         urs.email = 'test@gmail.com';
         urs.Alias='abcd';
         urs.Username='testdone@test.com';
         urs.CommunityNickname='abcd';
         urs.isactive=true;
         urs.EmailEncodingKey='UTF-8';
         urs.timezonesidkey='America/Los_Angeles';
         urs.LocaleSidKey='en_US';
         urs.languagelocalekey='en_US';
         urs.ProfileId= p.id;
         insert urs;

Apexpages.Standardcontroller controller=new Apexpages.StandardController(urs);
EFAjaxRemotingFunctionsController ef =new EFAjaxRemotingFunctionsController(controller);
EFAjaxRemotingFunctionsController.getUserData(urs.Id);
   }
}

ping me if your are not so reaching your requirment

or else

Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You,
Srinivas
SFDC Certified Developer




This was selected as the best answer
Raja.PRaja.P
Hi Sri 
Thank u so much 
Its been perfect without any change just copy paste ........ 

I am so kindful to u