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
Sai Kiran 1846Sai Kiran 1846 


public without sharing class X311Portal_EditProfileCtrl {
    public static Map<String, Object> getContactDetails(){
        Map<String, Object> returnMap = new Map<String, Object>();
        User userRecord = [SELECT Id, AccountId, ContactId FROM User WHERE Id =: UserInfo.getUserId()];
        Account personAccRecord = [SELECT FirstName, LastName, PersonEmail, Phone, PersonMailingCity, PersonMailingState,
                                    PersonMailingPostalCode, PersonMailingStreet FROM Account WHERE Id =: userRecord.AccountId];
        returnMap.put('personAccRecord', personAccRecord);
        return returnMap; 

    public static void updateContactDetails(String record) {
        Account accountRecord = (Account) JSON.deserialize(record, Account.class);
        upsert accountRecord;
Sai Kiran 1846Sai Kiran 1846
can anyone guide me how to write a test class for the above class?
Neha Arora 50Neha Arora 50
In your test class

//Create person account 
Use System.runAs(user){
  //create user record where userId.Account = personAccId
    //Invoke your class - X311Portal_EditProfileCtrl.getContactDetails();

Let me know if it helps.
AnkaiahAnkaiah (Salesforce Developers) 
Hi Sai,

try with below code.
public class X311Portal_EditProfileCtrlTest {
static testmethod void getContactDetailsmethod(){
Set<String> customerUserTypes = new Set<String> {'CSPLiteUser', 'PowerPartner', 'PowerCustomerSuccess',   'CustomerSuccess'};
Account acc = new Account (
FirstName ='test acc', 
LastName = 'last', 
PersonEmail = '',
PersonMailingCity = 'chennai', 
PersonMailingState = 'TamilNadu',
PersonMailingPostalCode ='600119,
PersonMailingStreet = 'test'
insert acc;
string acct = 'newAcc1';
Contact con = new Contact (
AccountId =,
LastName = 'portalTestUser'
insert con;
//UserRole ur = [Select PortalType, PortalAccountId From UserRole where PortalType =:'wipro Customer User' limit 1];
Profile p = [select Id,name from Profile where UserType in :customerUserTypes limit 1];
User newUser = new User(
//UserRoleId = ur.Id,
profileId =,
username = '',
email = '',
emailencodingkey = 'UTF-8',
localesidkey = 'en_US',
languagelocalekey = 'en_US',
timezonesidkey = 'America/Los_Angeles',
contactId =,
insert newUser; 



If this helps, Please mark it as best answer.