• rajubalaji
  • NEWBIE
  • 60 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 24
    Questions
  • 31
    Replies
Hi everyone,

Anyone know how to write a test class for elow code please help me.

    public Data Data{get;set;}
    public TrackerData TrackerData{get;set;}
    public DTO Info{get;set;}
    public InfoDTO Info{get;set;}

Thanks
RajuBalaji
Hi Everyone,

i was new to Article base concept,if any one have idea please give a hierarchy of article type.i means like flowchart.

if possible please help me.

Thanks Inadvance,
RajuBalaji
Hi evryone,

how to write test class for below code if any one know please help me  and if possible please explain me.

public String getFieldByName(ProspectUser__c prospectUser, String fieldName ){
        if(fieldName.equals('FirstName')){
                return prospectUser.FirstName__c;
            }else if(fieldName.equals('LastName')){
                return prospectUser.LastName__c;
            }else if(fieldName.equals('Gender')){
                return prospectUser.Gender__c;
            }else if(fieldName.equals('Email')){
                return prospectUser.Email__c;
            }else if(fieldName.equals('DateOfBirth')){
                return String.valueOf(prospectUser.DOB__c.format());
            }else if(fieldName.trim().equalsIgnoreCase('MemberId')){
                return prospectUser.Member_ID__c;
            }else{
                return '';
            }
    }

thanks inadvance,
raju
Hello Devs,
    Not sure what i have to modify in btach test class to make it 75% coverage , but right now it's only giving me 7%, any help is appreciated.please help me.

public class PendingUserTaskCreation implements Database.Batchable<Account>, Database.AllowsCallouts {
    public PendingUserTaskCreation() {
        
    }
    
    // Start Method
    public Iterable<Account> start(Database.BatchableContext BC){
        List<Account> lstAccount = [Select Id, Name, starId__c, Enviornment_Code__c from Account Where Pending_User_Task__c = true];
        return lstAccount;
    }
    
    // Execute Logic
    public void execute(Database.BatchableContext BC, List<Account> lstAccount){
        try {
            Datetime registrationStartDay = Datetime.now().date().addDays(-Integer.valueOf(Label.Registration_Task_Pending_Days));
            Date duedate = Utility.addBusinessdays(0);
            Integer count = 1;
            List<User> lstUser = Utility.GetUserListForTaskAssignment(lstAccount.get(0).Id, Label.Registration_Task);
            string recordTypeId = Utility.getRecordTypeID(Label.Registration_Task);
            List<Task> lstTasks = new List<Task>();
            for (Hub_Parent__c pt : [Select Id, AccountId__c, Registration_Completed_Date__c, Star_Display__c, (Select Id, Status, Type, CreatedDate from Tasks where Type =: Label.Registration_Task Order By CreatedDate desc Limit 1) from Hub_Parent__c Where AccountID__c = :lstAccount.get(0).Id and Product_Status__c = 'LoginPending' and Registration_Completed_Date__c <: registrationStartDay]) {
                if (pt.Tasks.size() == 0) {
                    Task objTask = new Task();
                    objTask.Type = 'Registration Task';
                    objTask.Status = 'Open';
                    objTask.Priority = 'High';
                    objTask.OwnerId = lstUser[(Integer)math.mod(count, lstUser.size())].Id;
                    count = count + 1;
                    objTask.WhatId = pt.Id;
                    objTask.Parents__c = pt.Id;
                    objTask.Account__c = pt.AccountId__c;
                    objTask.ActivityDate = duedate;
                    objTask.Description__c = Label.Registration_Task_Description;
                    objTask.IsVisibleInSelfService = true;
                    objTask.RecordTypeId = recordTypeId;
                    lstTasks.add(objTask);
                }
            }
            if (lstTasks.size() > 0) {
                List<Database.SaveResult> lstResult = Database.insert(lstTasks, false);
                String message = '';
                for (Database.SaveResult result:lstResult) {
                    if (!result.isSuccess()) {
                        Database.Error[] errs = result.getErrors();
                        for(Integer i=0;i<errs.size();i++){
                            message = message + '\\n' + errs[i].getMessage(); 
                        }
                    }
                }
                if (message != '') {
                    System.debug('PendingUserTaskCreation Error : ' + message);
                }
            }
        }
        catch (Exception ex) {
            System.debug('PendingUserTaskCreation Exception for Account - ' + lstAccount.get(0).Id + ' : ' + ex.getMessage());
        }
    }
    
    // Logic to be Executed at finish
    public void finish(Database.BatchableContext BC){
        
    }
}

Thanks Inadvance,
RajuBalaji.

Please help me with explaination if possible.
Hi Everyone,

if anyone find error in my apex class and please guide me.Actually i was new to write a programs.thanks you very much for helping me.

Apex class:

@RestResource(urlMapping='/DeleteInfo/*')
global class DeleteInfo {
@HttpPost
    global static String doPost() {
        String responseJSON;
        if (RestContext.request.requestBody != null) {
            String requestStatus;
            String reqBody = RestContext.request.requestBody.toString();
            String ParentId = null;
            Request Request = new Request();
            String environmentCode = Utility.getEnvironmentCode(UserInfo.getUserName());
            
            try {
                Req req = (Req)JSON.deserialize(reqBody, DeleteInfo.Req.class);
                Request = req.Request;
                
                if (Request.Parent != null) {
                    if (Request.Parent.StarID != null && Request.Parent.StarID != '') {
                        String ParentStarID = Request.Parent.StarID + '__' + environmentCode;
                        List<Hub_Parent__c> ptList = [select Id from Hub_Parent__c where StarID__c = :ParentStarID Limit 1];
                        
                        if (ptList.size() > 0) {
                            Hub_Parent__c objParent = ptList[0];
                            ParentId = objParent.Id;
                            
                            ParentDataDelete.DataDelete(objParent.Id);
                            
                            //List<ParentPrescription__c> lstParentPrescription = [select Id, Status__c from ParentPrescription__c Where Parents__c = :ParentId order by RxExpirationDate__c desc NULLS LAST, LastModifiedDate Desc limit 1];
                            
                            /*if (objParent.Prescriptions__r.size() > 0) {
                                ParentPrescription__c objParentPrescription = objParent.Prescriptions__r[0];
                                if (Request.Prescription.Status != null && (Request.Prescription.Status == 1 || Request.Prescription.Status == 2)) {
                                    String prescriptionStatus = Request.Prescription.Status == 1 ? 'Active' : 'Inactive';
                                    if (prescriptionStatus != objParentPrescription.Status__c) {
                                        objParentPrescription.Status__c = prescriptionStatus;
                                        update objParentPrescription;
                                    }
                                    responseJSON = InboundTransactionResponse.GetSucessResponse(Request.Header.TransactionType, Request.Header.TimeStamp, Request.Header.FileID, Request.Prescription.StarID);
                                    requestStatus = 'Success';
                                }
                                else {
                                    responseJSON = InboundTransactionResponse.GetErrorResponse(Request.Header.TransactionType, Request.Header.TimeStamp, Request.Header.FileID, Request.Prescription.StarID, 'Status', '0056', 'Invalid Prescription Status');
                                    requestStatus = 'Failure';
                                }
                            }
                            else {
                                responseJSON = InboundTransactionResponse.GetErrorResponse(Request.Header.TransactionType, Request.Header.TimeStamp, Request.Header.FileID, Request.Prescription.StarID, 'Prescription', '0056', 'Prescription doesn\'t exists in system for the Parent');
                                requestStatus = 'Failure';
                            }*/
                            responseJSON = InboundTransactionResponse.GetSucessResponse(Request.Header.TransactionType, Request.Header.TimeStamp, Request.Header.FileID, Request.Parent.StarID);
                            requestStatus = 'Success';
                        }
                        else {
                            responseJSON = InboundTransactionResponse.GetErrorResponse(Request.Header.TransactionType, Request.Header.TimeStamp, Request.Header.FileID, Request.Parent.StarID, 'StarID', '0056', 'StarID doesn\'t exists in system');
                            requestStatus = 'Failure';
                        }
                    }
                    else {
                        responseJSON = InboundTransactionResponse.GetErrorResponse(Request.Header.TransactionType, Request.Header.TimeStamp, Request.Header.FileID, null, 'StarID', '001', 'StarID is a required field.');
                        requestStatus = 'Failure';
                    }
                }
                else {
                    responseJSON = InboundTransactionResponse.GetErrorResponse(Request.Header.TransactionType, Request.Header.TimeStamp, Request.Header.FileID, null, 'Parent', '001', 'Invalid request format.');
                    requestStatus = 'Failure';
                }
                BlueStarTransactionDetails.CreateInboundTransactionRequest(Request.Header.TransactionType, Request.Header.FileID, requestStatus, reqBody, responseJSON, null, null, null, environmentCode);
            }
            catch (Exception ex) {
                System.debug('Delete Exception: ' + ex.getMessage());
                String fileId;
                if (Request.Header != null && Request.Header.FileID != null) {
                    fileId = Request.Header.FileID;
                }
                else {
                    fileId = 'Unknown';
                }
                BlueStarTransactionDetails.CreateInboundTransactionRequest(Request.Header.TransactionType, fileId, 'Exception', reqBody, ex.getMessage(), null, null, null, environmentCode);
                if(Request != null && Request.Header != null){
                    responseJSON = InboundTransactionResponse.GetErrorResponse(Request.Header.TransactionType, Request.Header.TimeStamp, Request.Header.FileID, null, 'Error', '0056', ex.getMessage());
                }else{
                    responseJSON = ex.getMessage();
                }
            }
        }
        return responseJSON;
    }
    
    public class Parent {
        public String StarID {get;set;}
    }
    
    public class Header {
        public String TransactionType {get;set;}
        public String TimeStamp {get;set;}
        public String FileID {get;set;}
    }
    
    public class Request {
        public Parent Parent {get;set;}
        public Header Header {get;set;}
    }
    
    public class Req {
        public Request Request {get;set;}
    }
}


Test Class for above Apex class:

@isTest
public class DeleteInfo_Test {
    static testMethod void TestDeleteInfo(){
        
        Test.startTest();
        HubTestController.createCustomSettings();
        //User usr = [Select Id from User where UserName = 'bluestar@welldocinc.com.sfdev4' Limit 1];
        List<User> usr = [Select Id,UserName from User where Name = 'bluestar bluestar' Limit 1];
        system.runAs(usr[0]){
            HubTestController.createEnviornmentSettingsWithUserName(usr[0].UserName);
            Hub_parent__c parent = new Hub_parent__c();
            parent.GivenName__c = 'Mangesh';
            parent.SampleCode__c = 'SCA1556329';
            parent.FamilyName__c = 'K';
            parent.Status__c = 'SRF Incomplete';
            parent.StarID__c ='StarID__bst';
            parent.FamilyName__c = 'K';
            parent.DOB__c = System.today();
            parent.Gender__c = 'M';
            
            insert parent;  
            RestRequest req = new RestRequest();
            RestResponse res = new RestResponse();
            
            String str ='{"Request":{"Header":{"TransactionType":"DeleteInfo","TimeStamp":"03-15-2016 12:09:15:252","FileID":"DeleteInfo.03152016120915252"},"parent":{"StarID":"StarID","Status":"Pending"}}}';
            req.requestURI = '/DeleteInfo/*';  
            req.httpMethod = 'Post';
            RestContext.request = req;
            RestContext.request.requestBody = Blob.valueOf(str);
            RestContext.response = res;
            String results = DeleteInfo.doPost();
            
            str = '{"Request":{"Header":{"TransactionType":"DeleteInfo","TimeStamp":"03-15-2016 12:09:15:252","FileID":"DeleteInfo.03152016120915252"},"parent":{"StarID":"StarID","AccountCode":"WD","SampleCode":"SampleCode"}}}';
            req.requestURI = '/DeleteInfo/*';  
            req.httpMethod = 'Post';
            RestContext.request = req;
            RestContext.request.requestBody = Blob.valueOf(str);
            RestContext.response = res;
            DeleteInfo.doPost();
            
            str = '{"Request":{"Header":{"TransactionType":"DeleteInfo","TimeStamp":"03-15-2016 12:09:15:252","FileID":"DeleteInfo.03152016120915252"},"parent":{"StarID":"StarID","AccountCode":"WD","SampleCode":"SampleCode"}}}';
            req.requestURI = '/DeleteInfo/*';  
            req.httpMethod = 'Post';
            RestContext.request = req;
            RestContext.request.requestBody = Blob.valueOf(str);
            RestContext.response = res;
            DeleteInfo.doPost();
            
            Str = '{"Request":{"Header":{"TransactionType":"DeleteInfo","TimeStamp":"03-15-2016 12:09:15:252","FileID"!=""},"parent":{"StarID"!="","AccountCode"!="","SampleCode"!=""}}}';
            req.requestURI = '/DeleteInfo/*';  
            req.httpMethod = 'Post';
            RestContext.request = req;
            req.requestBody = Blob.valueOf(str);
            RestContext.response = res;
            DeleteInfo.doPost();

            Test.stopTest();
        }
    }
}


Here i was facing issue was code was almost covered but while run the test class i was showing error.

"System.NullPointerException: Attempt to de-reference a null object".


if anyone please help me.


Thanks INadvance,
RajuBalaji
Hi Everyone,

I am new to write a apex in test classes.if anyone please help me how to write a test class for below code and if possible please explain me line by line it will really helpful for me.

Apex Class:
if (Request.Parent != null) {
                    if (Request.Parent.StarID != null && Request.Parent .StarID != '') {
                        String Parent StarID = Request.Parent .StarID + '__' + environmentCode;
                        List<Hub_Parent __c> ptList = [select Id from Hub_Parent __c where StarID__c = :ParentStarID Limit 1];
                        
                        if (ptList.size() > 0) {
                            Hub_Parent __c objParent = ptList[0];
                            ParentId = objParent.Id;
                            
                            Parent DataDelete.DataDelete(objParent .Id);

catch (Exception ex) {
                System.debug('Delete Exception: ' + ex.getMessage());
                String fileId;
                if (Request.Header != null && Request.Header.FileID != null) {
                    fileId = Request.Header.FileID;
                }
                else {
                    fileId = 'Unknown';
                }
                StarTransactionDetails.CreateInboundTransactionRequest(Request.Header.TransactionType, fileId, 'Exception', reqBody, ex.getMessage(), null, null, null, environmentCode);
                if(Request != null && Request.Header != null){
                    responseJSON = InboundTransactionResponse.GetErrorResponse(Request.Header.TransactionType, Request.Header.TimeStamp, Request.Header.FileID, null, 'Error', '0056', ex.getMessage());
                }else{
                    responseJSON = ex.getMessage();
                }
            }


Thanks Inadvance,
RajuBalaji
Hi Everyone,

I was new to write a apex test class.please find the below code and help me how to write a test class for that and if possible please explain me line by line it well really helpful for me.Thanks inadvance.

@RestResource(urlMapping='/DeleteInfo/*')
global class DeleteInfo {
@HttpPost
    global static String doPost() {
        String responseJSON;
        if (RestContext.request.requestBody != null) {
            String requestStatus;
            String reqBody = RestContext.request.requestBody.toString();
            String parentId = null;
            Request Request = new Request();
            String environmentCode = Utility.getEnvironmentCode(UserInfo.getUserName());
            
            try {
                Req req = (Req)JSON.deserialize(reqBody, DeleteInfo.Req.class);
                Request = req.Request;
                
                if (Request.parent != null) {
                    if (Request.parent.StarID != null && Request.parent.StarID != '') {
                        String parentStarID = Request.parent.StarID + '__' + environmentCode;
                        List<Hub_Parent__c> ptList = [select Id from Hub_Parent__c where StarIDt__c = :parentStarID Limit 1];
                        
                        if (ptList.size() > 0) {
                            Hub_Parent__c objparent = ptList[0];
                            parentId = objparent.Id;
                            
                            DataDelete.DataDelete(objParent.Id);
                            
                            responseJSON = InboundTransactionResponse.GetSucessResponse(Request.Header.TransactionType, Request.Header.TimeStamp, Request.Header.FileID, Request.parent.StarID);
                            requestStatus = 'Success';
                        }
                        else {
                            responseJSON = InboundTransactionResponse.GetErrorResponse(Request.Header.TransactionType, Request.Header.TimeStamp, Request.Header.FileID, Request.parent.StarID, 'StarID', '0056', 'StarID doesn\'t exists in system');
                            requestStatus = 'Failure';
                        }
                    }
                    else {
                        responseJSON = InboundTransactionResponse.GetErrorResponse(Request.Header.TransactionType, Request.Header.TimeStamp, Request.Header.FileID, null, 'StarID', '001', 'StarID is a required field.');
                        requestStatus = 'Failure';
                    }
                }
                else {
                    responseJSON = InboundTransactionResponse.GetErrorResponse(Request.Header.TransactionType, Request.Header.TimeStamp, Request.Header.FileID, null, 'parent', '001', 'Invalid request format.');
                    requestStatus = 'Failure';
                }
                BlueStarTransactionDetails.CreateInboundTransactionRequest(Request.Header.TransactionType, Request.Header.FileID, requestStatus, reqBody, responseJSON, null, null, null, environmentCode);
            }
            catch (Exception ex) {
                System.debug('Delete Exception: ' + ex.getMessage());
                String fileId;
                if (Request.Header != null && Request.Header.FileID != null) {
                    fileId = Request.Header.FileID;
                }
                else {
                    fileId = 'Unknown';
                }
                BlueStarTransactionDetails.CreateInboundTransactionRequest(Request.Header.TransactionType, fileId, 'Exception', reqBody, ex.getMessage(), null, null, null, environmentCode);
                if(Request != null && Request.Header != null){
                  responseJSON = InboundTransactionResponse.GetErrorResponse(Request.Header.TransactionType, Request.Header.TimeStamp, Request.Header.FileID, null, 'Error', '0056', ex.getMessage());
                }else{
                    responseJSON = ex.getMessage();
                }
            }
        }
        return responseJSON;
    }
    
    public class parent {
        public String StarID {get;set;}
    }
    
    public class Header {
        public String TransactionType {get;set;}
        public String TimeStamp {get;set;}
        public String FileID {get;set;}
    }
    
    public class Request {
        public parent parent {get;set;}
        public Header Header {get;set;}
    }
    
    public class Req {
        public Request Request {get;set;}
    }
}

Thanks inadvance.
Hi Everyone,

How to write a program in apex class for delete a task object and i need to get status and see if delete task was success or not.

if anyone know please help me.thanks inadvance.

thanks,
balaji
Hi Team,

Here i need to write a program to delete the data,if any one knows please help me.
whenever we call that method with taskid,it will delete all the data from that task.

please help me.

thanks,
Balaji
Hi Everyone,

Can anyone please explain me how to import data from one salesforce to another salesforce without changing the id values.

Thanks inadvance
Hi everyOne.

How to show the standard date time functionality in vf page.

User-added imagesame like this how can i created in visual force page with select list of time 8:00AM to 7:00PM with the interval of 15 mintues.

if any one have idea please help me with syntax.

thanks inadvance.
p.Balu
Hi Everyone,

If Anyone have idea please help me on this issue.

Here my Scenairo was we have one task page when user are creating for the sales team.How can i create a follow up time for task object and with a link of follow up date with apex controller class also.i need to get the reminder popup window notification alert before 15 mintues of due time for that user to completed the task.
In this way i dont want to use workflow r task reminders is there any different way to achieve this.if anyone have idea please help me on this issue.

thanks inadvance,
p.balu
Hi everyone,

I have one doubt.is there any specific reminder field column in salesforce.Means if i have created one task and one event after due day and dimiss all then that reminder where it will save.if any one have idea please help me.

Thanks Inadvance.
P.Balu 
Hi Everyone,

I need to know that in how many ways i can create a task popup window reminder notofications for follow up time.If anyone have idea please share with me and if possible please explain me as well.

Thanks for ur help.

thanks inadvance,
P.Balu 
Hi everyone,

Can anyone please guide my how to write a map<string> and list<string> together.please find below code and help me on this issue.

Map<String, Map<String, List<String>>> countryMap = new Map<String, Map<String, List<String>>> {'Germany' => 'German',  'Spain' => 'Spanish' ,  'France' => 'French' ,  'UnitedStates' => 'English' , 'UnitedStates' => 'Spanish' ,  'Canada' => 'English' , 'Canada' => 'French'};
            for(String c : newCountries){
                for(String l : newLanguages){
                    if(countrymap.containskey(c) && !Countrymap.get(c).contains(l)){
                        error = true;
                        account.adderror( 'country ' + c + ' does not support language ' + l);
                        return;
                    }
                }
            }

Thanks inadvance,
P.Balu
Hi everyone,

If any one have idea please guide me and explain me on these issue.

My Question was:

How Can i will  Provide unfiled public reports folder access & permission to create new reports for non-admin users.

So,please provide me and give my step by step for better understand.

Thanks Inadvance.

P.Balaji Karthik
Hi everyOne,

I have written one test class while run it was showing success but while checking in apex class code coverage was zero.if any one have idea please guide me how to overcome with this issue.

Thanks InAdvance.

Regards,
Balaji
Hello everyone,

i'm developing a webservice in rest and i have no idea about how write a test class in this case and this is my code.Please anyone help.

@RestResource(urlMapping='/BulkPatientDeactivationResponse/*')
global class BulkPatientDeactivationResponse {
    @HttpPost
    global static void doPost() {
        if (RestContext.request.requestBody != null) {
            Savepoint sp = Database.setSavepoint();
            try {
                String environmentCode = Utility.getEnvironmentCode(UserInfo.getUserName());
                
                String reqBody = RestContext.request.requestBody.toString();
                if (reqBody.contains('Header')) {
                    TranRes res = (TranRes)JSON.deserialize(reqBody, BulkPatientDeactivationResponse.TranRes.class);
                    String fileName = 'Unknown', type = 'Unknown', status = 'Unknown';
                    if (res.Response.Header.FileID != null) {
                        fileName = res.Response.Header.FileID;
                    }
                    if (res.Response.Header.TransactionType != null) {
                        type = res.Response.Header.TransactionType;
                    }
                    if (res.Response.Header.Status != null) {
                        status = res.Response.Header.Status;
                    }
                    List<TransactionDetail__c> tranList = [select Id, Transaction_Status__c, Response_JSON__c, HUB_Practice__c, HUB_Provider__c, Comments__c, Request_JSON__c from TransactionDetail__c where FileID__c = :fileName and Name = :type Limit 1];
                    
                    if (res.Response.ResponseType.AccountCode != null && res.Response.ResponseType.AccountCode != '') {
                        List<Account> lstAccount = [Select Id, Model_Number__c from Account where BluestarId__c =: res.Response.ResponseType.AccountCode and Enviornment_Code__c = :environmentCode Limit 1];
                        if (lstAccount.size() > 0) {
                            TransactionDetail__c transDetail = tranList.get(0);
                            BulkPatientDeactivationController.BulkPatientDeactivation bulkPatientDeactivationUser = (BulkPatientDeactivationController.BulkPatientDeactivation)JSON.deserialize(transDetail.Request_JSON__c, BulkPatientDeactivationController.BulkPatientDeactivation.class);
                            
                            if (res.Response.ResponseType.SuccessUsers != null && res.Response.ResponseType.SuccessUsers != '') {
                                Attachment file = new Attachment();
                                file.name = bulkPatientDeactivationUser.Request.Patient.Data + '-SuccessBulkDeactivationUsers' + '.json';
                                file.parentId = lstAccount[0].Id;
                                file.body = Blob.valueOf(res.Response.ResponseType.SuccessUsers);
                                insert file;
                                
                                String successUsersContent = '{"User":' + res.Response.ResponseType.SuccessUsers + '}';
                                Users successUsers = (Users)JSON.deserialize(successUsersContent, BulkPatientDeactivationResponse.Users.class);
                                Integer userCount = successUsers.User.size();
                                
                                List<String> lstBlueStarIDs = new List<String>();
                                for (Integer i = 0; i < userCount; i++) {
                                    lstBlueStarIDs.Add(successUsers.User[i].BlueStarID + '__' + environmentCode);
                                }
                                
                                List<Hub_Patient__c> lstPatients = [select Id, BlueStarID__c from Hub_Patient__c where BlueStarID__c in :lstBlueStarIDs];
                                
                                List<Hub_Patient__c> lstPatientsToDeactivate = new List<Hub_Patient__c>();
                                List<Id> deactivationPatients = new List<Id>();
                                for (Hub_Patient__c usr:lstPatients){
                                    deactivationPatients.Add(usr.Id);
                                    
                                    //Update Patient Status
                                    usr.Product_Status__c = 'Inactive';
                                    usr.ProductStatusReason__c = bulkPatientDeactivationUser.Request.Patient.DeactivateReason;
                                    usr.Status__c = Label.HubStat_Inactive;
                                    lstPatientsToDeactivate.Add(usr);
                                }
                                                                
                                //CheckAndCloseAllTaskForPatients
                                List<Task> lstTask = [select Id, Type, Status from Task where WhatId in :deactivationPatients and Type != :Label.TaskType_PatientDrivenFailure and Status != 'Closed'];
                                if (lstTask.size() > 0) {
                                    for (Integer j = 0; j < lstTask.size(); j++) {
                                        lstTask[j].Status = 'Closed';
                                    }
                                    update lstTask;
                                }
                                
                                List<TransactionDetail__c> lstTran = new List<TransactionDetail__c>();
                                if (lstPatientsToDeactivate.size() > 0) {
                                    List<Database.SaveResult> lstResult = Database.update(lstPatientsToDeactivate, false);
                                    for (Integer i = 0; i < lstResult.size(); i++) {
                                        if (!lstResult[i].isSuccess()) {
                                            String message = null;
                                            Database.Error[] errs = lstResult[i].getErrors();
                                            for (Integer j = 0; j < errs.size(); j++){
                                                message = message + '\\n' + errs[j].getStatusCode() + ': ' + errs[j].getMessage() + '.'; 
                                            }
                                            TransactionDetail__c tran = new TransactionDetail__c();
                                            tran.Name = 'BulkPatientDeactivationFailure';
                                            tran.Transaction_Type__c = 'Inbound';
                                            tran.Transaction_Status__c = 'Exception';
                                            tran.Account__c = lstAccount[0].Id;
                                            tran.Request_JSON__c = JSON.serialize(successUsers.User[i]);
                                            tran.Response_JSON__c = message;
                                            lstTran.add(tran);
                                        }
                                    }
                                }
                                if (lstTran.size() > 0) {
                                    Database.insert(lstTran, false);
                                }
                            }
                            
                            if (res.Response.ResponseType.FailureUsers != null && res.Response.ResponseType.FailureUsers != '') {
                                Attachment file = new Attachment();
                                file.name = bulkPatientDeactivationUser.Request.Patient.Data + '-FailureBulkDeactivationUsers' + '.json';
                                file.parentId = lstAccount[0].Id;
                                file.body = Blob.valueOf(res.Response.ResponseType.FailureUsers);
                                insert file;
                                
                                TransactionDetail__c tran = new TransactionDetail__c();
                                tran.Name = 'BulkPatientDeactivationFailure';
                                tran.Transaction_Type__c = 'Inbound';
                                tran.Transaction_Status__c = 'Exception';
                                tran.Account__c = lstAccount[0].Id;
                                tran.Request_JSON__c = 'Error Deactivating Users in product. Error Deactivation Users details : ' + res.Response.ResponseType.FailureUsers;
                                tran.Response_JSON__c = 'Error Deactivating Users in product.';
                                Database.insert(tran);
                            }
                        }
                    }
                    
                    if (tranList.size() > 0) {
                        TransactionDetail__c tran = tranList[0];
                        tran.Transaction_Status__c = status;
                        tran.Response_JSON__c = reqBody;
                        update tran;
                    }
                    else {
                        BlueStarTransactionDetails.CreateUnknownTransactionResponse(fileName, status, reqBody);
                    }
                }
                else if (reqBody.contains('SchemaError')) {
                    SchemaErrorTran schemaErr = (SchemaErrorTran)JSON.deserialize(reqBody, BulkPatientDeactivationResponse.SchemaErrorTran.class);
                    System.debug(schemaErr);
                    if (schemaErr.Response.SchemaError.FileName != null) {
                        String fileName = schemaErr.Response.SchemaError.FileName.replace('SD_WD_', '').replace('_', '.').replace('.xml', '');
                        String tranStatus = 'Failure: ';
                        if (schemaErr.Response.SchemaError.ErrorText != null) {
                            if (schemaErr.Response.SchemaError.ErrorText.length() > 23) {
                                tranStatus = tranStatus + schemaErr.Response.SchemaError.ErrorText.substring(0, 22);
                            }
                            else {
                                tranStatus = tranStatus + schemaErr.Response.SchemaError.ErrorText;
                            }
                        }
                        List<TransactionDetail__c> tranList = [select Id, Transaction_Status__c, Response_JSON__c from TransactionDetail__c where FileID__c = :fileName Limit 1];
                        if (tranList.size() > 0) {
                            TransactionDetail__c tran = tranList[0];
                            tran.Transaction_Status__c = tranStatus;
                            tran.Response_JSON__c = reqBody;
                            update tran;
                        }
                        else {
                            BlueStarTransactionDetails.CreateUnknownTransactionResponse(schemaErr.Response.SchemaError.FileName, tranStatus, reqBody);
                        }
                    }
                    else {
                        BlueStarTransactionDetails.CreateUnknownTransactionResponse('Unknown', 'Unknown', reqBody);
                    }
                }
                else {
                    BlueStarTransactionDetails.CreateUnknownTransactionResponse('Unknown', 'Unknown', reqBody);
                }
            } catch (Exception ex) {
                Database.rollback(sp);
                String resp = RestContext.request.requestBody.toString();
                BlueStarTransactionDetails.CreateErrorProcessingTransactionResponse('Unknown', 'Exception', resp, ex.getMessage());
            }
        }
    }
    
    public class TranHeader {
        public String TransactionType;
        public String TimeStamp;
        public String FileID;
        public String Status;
    }
    
    public class ResType {
        public String HubCode {get;set;}
        public String BlueStarID {get;set;}
        public String AccountCode {get;set;}
        public String SuccessUsers {get;set;}
        public String FailureUsers {get;set;}
        public String FailedUsers {get;set;}
    }
    
    public class TranResp {
        public TranHeader Header;
        public ResType ResponseType;
    }
    
    public class TranRes {
        public TranResp Response;
    }
    
    public class SchemaErr {
        public String FileName {get;Set;}
        public String ErrorText {get;set;}
    }
    
    public class SchemaErrorResp {
        public SchemaErr SchemaError;
    }
    
    public class SchemaErrorTran {
        public SchemaErrorResp Response;
    }
    
    public class Users {
        List<DeactivationUser> User {get;set;}
    }
    
    public Class DeactivationUser {
        String Email {get;set;}
        String BlueStarID {get;set;}
    }
}

Please any one help me.

Thanks Inadvance
Dear friends,

How can i cover following line in test class.

public boolean Checked{get;set;}  //  This line is not covering in the test class.

if(att.Body != null) {
                        newBody = EncodingUtil.base64Encode(att.Body);
                    }

If anyBody Have idea please help me.

Thanks in advance.
 
Hi everyone,

I am new to salesforce developer domain.Please help me for futher process.

please find the below visual force page here i need to create apex class for the check box functiontality.please guide me.

    <apex:pageBlockSection columns="1" id="block1" title="Deactivation List" collapsible="false">
                    
                    <apex:pageBlockSectionItem >
                        <apex:outputLabel value="CSV File : "/>
                            <input type="file" name="files[]" multiple="multiple" onchange="prepareFiles(this);"/>
                       </apex:pageBlockSectionItem>
                    
                    <apex:pageBlockSectionItem>
                        <apex:outputLabel value="Deactivation Reason: "/>
                        <select Id="ddlDeactivationReason">
                            <option value="-1">--None--</option>
                            <option value="4">Access code &#38; send email</option>
                            <option value="1">Access code &#38; suppress email</option>
                            <option value="3">Invitation link &#38; send email</option>
                            <option value="2">Invitation link &#38; suppress email</option>
                            <option value="5">Eligibility Verification</option>
                        </select>
                    </apex:pageBlockSectionItem>
                
                      <apex:pageBlockSectionItem>Suppress Email:
                          <apex:inputCheckbox/>
                    </apex:pageBlockSectionItem>     

         </apex:pageBlockSection>            
        </apex:pageBlock>
please help to create apex class controller for this class with explaination.

thanks in advance
Hi evryone,

how to write test class for below code if any one know please help me  and if possible please explain me.

public String getFieldByName(ProspectUser__c prospectUser, String fieldName ){
        if(fieldName.equals('FirstName')){
                return prospectUser.FirstName__c;
            }else if(fieldName.equals('LastName')){
                return prospectUser.LastName__c;
            }else if(fieldName.equals('Gender')){
                return prospectUser.Gender__c;
            }else if(fieldName.equals('Email')){
                return prospectUser.Email__c;
            }else if(fieldName.equals('DateOfBirth')){
                return String.valueOf(prospectUser.DOB__c.format());
            }else if(fieldName.trim().equalsIgnoreCase('MemberId')){
                return prospectUser.Member_ID__c;
            }else{
                return '';
            }
    }

thanks inadvance,
raju
Hi Everyone,

if anyone find error in my apex class and please guide me.Actually i was new to write a programs.thanks you very much for helping me.

Apex class:

@RestResource(urlMapping='/DeleteInfo/*')
global class DeleteInfo {
@HttpPost
    global static String doPost() {
        String responseJSON;
        if (RestContext.request.requestBody != null) {
            String requestStatus;
            String reqBody = RestContext.request.requestBody.toString();
            String ParentId = null;
            Request Request = new Request();
            String environmentCode = Utility.getEnvironmentCode(UserInfo.getUserName());
            
            try {
                Req req = (Req)JSON.deserialize(reqBody, DeleteInfo.Req.class);
                Request = req.Request;
                
                if (Request.Parent != null) {
                    if (Request.Parent.StarID != null && Request.Parent.StarID != '') {
                        String ParentStarID = Request.Parent.StarID + '__' + environmentCode;
                        List<Hub_Parent__c> ptList = [select Id from Hub_Parent__c where StarID__c = :ParentStarID Limit 1];
                        
                        if (ptList.size() > 0) {
                            Hub_Parent__c objParent = ptList[0];
                            ParentId = objParent.Id;
                            
                            ParentDataDelete.DataDelete(objParent.Id);
                            
                            //List<ParentPrescription__c> lstParentPrescription = [select Id, Status__c from ParentPrescription__c Where Parents__c = :ParentId order by RxExpirationDate__c desc NULLS LAST, LastModifiedDate Desc limit 1];
                            
                            /*if (objParent.Prescriptions__r.size() > 0) {
                                ParentPrescription__c objParentPrescription = objParent.Prescriptions__r[0];
                                if (Request.Prescription.Status != null && (Request.Prescription.Status == 1 || Request.Prescription.Status == 2)) {
                                    String prescriptionStatus = Request.Prescription.Status == 1 ? 'Active' : 'Inactive';
                                    if (prescriptionStatus != objParentPrescription.Status__c) {
                                        objParentPrescription.Status__c = prescriptionStatus;
                                        update objParentPrescription;
                                    }
                                    responseJSON = InboundTransactionResponse.GetSucessResponse(Request.Header.TransactionType, Request.Header.TimeStamp, Request.Header.FileID, Request.Prescription.StarID);
                                    requestStatus = 'Success';
                                }
                                else {
                                    responseJSON = InboundTransactionResponse.GetErrorResponse(Request.Header.TransactionType, Request.Header.TimeStamp, Request.Header.FileID, Request.Prescription.StarID, 'Status', '0056', 'Invalid Prescription Status');
                                    requestStatus = 'Failure';
                                }
                            }
                            else {
                                responseJSON = InboundTransactionResponse.GetErrorResponse(Request.Header.TransactionType, Request.Header.TimeStamp, Request.Header.FileID, Request.Prescription.StarID, 'Prescription', '0056', 'Prescription doesn\'t exists in system for the Parent');
                                requestStatus = 'Failure';
                            }*/
                            responseJSON = InboundTransactionResponse.GetSucessResponse(Request.Header.TransactionType, Request.Header.TimeStamp, Request.Header.FileID, Request.Parent.StarID);
                            requestStatus = 'Success';
                        }
                        else {
                            responseJSON = InboundTransactionResponse.GetErrorResponse(Request.Header.TransactionType, Request.Header.TimeStamp, Request.Header.FileID, Request.Parent.StarID, 'StarID', '0056', 'StarID doesn\'t exists in system');
                            requestStatus = 'Failure';
                        }
                    }
                    else {
                        responseJSON = InboundTransactionResponse.GetErrorResponse(Request.Header.TransactionType, Request.Header.TimeStamp, Request.Header.FileID, null, 'StarID', '001', 'StarID is a required field.');
                        requestStatus = 'Failure';
                    }
                }
                else {
                    responseJSON = InboundTransactionResponse.GetErrorResponse(Request.Header.TransactionType, Request.Header.TimeStamp, Request.Header.FileID, null, 'Parent', '001', 'Invalid request format.');
                    requestStatus = 'Failure';
                }
                BlueStarTransactionDetails.CreateInboundTransactionRequest(Request.Header.TransactionType, Request.Header.FileID, requestStatus, reqBody, responseJSON, null, null, null, environmentCode);
            }
            catch (Exception ex) {
                System.debug('Delete Exception: ' + ex.getMessage());
                String fileId;
                if (Request.Header != null && Request.Header.FileID != null) {
                    fileId = Request.Header.FileID;
                }
                else {
                    fileId = 'Unknown';
                }
                BlueStarTransactionDetails.CreateInboundTransactionRequest(Request.Header.TransactionType, fileId, 'Exception', reqBody, ex.getMessage(), null, null, null, environmentCode);
                if(Request != null && Request.Header != null){
                    responseJSON = InboundTransactionResponse.GetErrorResponse(Request.Header.TransactionType, Request.Header.TimeStamp, Request.Header.FileID, null, 'Error', '0056', ex.getMessage());
                }else{
                    responseJSON = ex.getMessage();
                }
            }
        }
        return responseJSON;
    }
    
    public class Parent {
        public String StarID {get;set;}
    }
    
    public class Header {
        public String TransactionType {get;set;}
        public String TimeStamp {get;set;}
        public String FileID {get;set;}
    }
    
    public class Request {
        public Parent Parent {get;set;}
        public Header Header {get;set;}
    }
    
    public class Req {
        public Request Request {get;set;}
    }
}


Test Class for above Apex class:

@isTest
public class DeleteInfo_Test {
    static testMethod void TestDeleteInfo(){
        
        Test.startTest();
        HubTestController.createCustomSettings();
        //User usr = [Select Id from User where UserName = 'bluestar@welldocinc.com.sfdev4' Limit 1];
        List<User> usr = [Select Id,UserName from User where Name = 'bluestar bluestar' Limit 1];
        system.runAs(usr[0]){
            HubTestController.createEnviornmentSettingsWithUserName(usr[0].UserName);
            Hub_parent__c parent = new Hub_parent__c();
            parent.GivenName__c = 'Mangesh';
            parent.SampleCode__c = 'SCA1556329';
            parent.FamilyName__c = 'K';
            parent.Status__c = 'SRF Incomplete';
            parent.StarID__c ='StarID__bst';
            parent.FamilyName__c = 'K';
            parent.DOB__c = System.today();
            parent.Gender__c = 'M';
            
            insert parent;  
            RestRequest req = new RestRequest();
            RestResponse res = new RestResponse();
            
            String str ='{"Request":{"Header":{"TransactionType":"DeleteInfo","TimeStamp":"03-15-2016 12:09:15:252","FileID":"DeleteInfo.03152016120915252"},"parent":{"StarID":"StarID","Status":"Pending"}}}';
            req.requestURI = '/DeleteInfo/*';  
            req.httpMethod = 'Post';
            RestContext.request = req;
            RestContext.request.requestBody = Blob.valueOf(str);
            RestContext.response = res;
            String results = DeleteInfo.doPost();
            
            str = '{"Request":{"Header":{"TransactionType":"DeleteInfo","TimeStamp":"03-15-2016 12:09:15:252","FileID":"DeleteInfo.03152016120915252"},"parent":{"StarID":"StarID","AccountCode":"WD","SampleCode":"SampleCode"}}}';
            req.requestURI = '/DeleteInfo/*';  
            req.httpMethod = 'Post';
            RestContext.request = req;
            RestContext.request.requestBody = Blob.valueOf(str);
            RestContext.response = res;
            DeleteInfo.doPost();
            
            str = '{"Request":{"Header":{"TransactionType":"DeleteInfo","TimeStamp":"03-15-2016 12:09:15:252","FileID":"DeleteInfo.03152016120915252"},"parent":{"StarID":"StarID","AccountCode":"WD","SampleCode":"SampleCode"}}}';
            req.requestURI = '/DeleteInfo/*';  
            req.httpMethod = 'Post';
            RestContext.request = req;
            RestContext.request.requestBody = Blob.valueOf(str);
            RestContext.response = res;
            DeleteInfo.doPost();
            
            Str = '{"Request":{"Header":{"TransactionType":"DeleteInfo","TimeStamp":"03-15-2016 12:09:15:252","FileID"!=""},"parent":{"StarID"!="","AccountCode"!="","SampleCode"!=""}}}';
            req.requestURI = '/DeleteInfo/*';  
            req.httpMethod = 'Post';
            RestContext.request = req;
            req.requestBody = Blob.valueOf(str);
            RestContext.response = res;
            DeleteInfo.doPost();

            Test.stopTest();
        }
    }
}


Here i was facing issue was code was almost covered but while run the test class i was showing error.

"System.NullPointerException: Attempt to de-reference a null object".


if anyone please help me.


Thanks INadvance,
RajuBalaji
Hi Everyone,

I was new to write a apex test class.please find the below code and help me how to write a test class for that and if possible please explain me line by line it well really helpful for me.Thanks inadvance.

@RestResource(urlMapping='/DeleteInfo/*')
global class DeleteInfo {
@HttpPost
    global static String doPost() {
        String responseJSON;
        if (RestContext.request.requestBody != null) {
            String requestStatus;
            String reqBody = RestContext.request.requestBody.toString();
            String parentId = null;
            Request Request = new Request();
            String environmentCode = Utility.getEnvironmentCode(UserInfo.getUserName());
            
            try {
                Req req = (Req)JSON.deserialize(reqBody, DeleteInfo.Req.class);
                Request = req.Request;
                
                if (Request.parent != null) {
                    if (Request.parent.StarID != null && Request.parent.StarID != '') {
                        String parentStarID = Request.parent.StarID + '__' + environmentCode;
                        List<Hub_Parent__c> ptList = [select Id from Hub_Parent__c where StarIDt__c = :parentStarID Limit 1];
                        
                        if (ptList.size() > 0) {
                            Hub_Parent__c objparent = ptList[0];
                            parentId = objparent.Id;
                            
                            DataDelete.DataDelete(objParent.Id);
                            
                            responseJSON = InboundTransactionResponse.GetSucessResponse(Request.Header.TransactionType, Request.Header.TimeStamp, Request.Header.FileID, Request.parent.StarID);
                            requestStatus = 'Success';
                        }
                        else {
                            responseJSON = InboundTransactionResponse.GetErrorResponse(Request.Header.TransactionType, Request.Header.TimeStamp, Request.Header.FileID, Request.parent.StarID, 'StarID', '0056', 'StarID doesn\'t exists in system');
                            requestStatus = 'Failure';
                        }
                    }
                    else {
                        responseJSON = InboundTransactionResponse.GetErrorResponse(Request.Header.TransactionType, Request.Header.TimeStamp, Request.Header.FileID, null, 'StarID', '001', 'StarID is a required field.');
                        requestStatus = 'Failure';
                    }
                }
                else {
                    responseJSON = InboundTransactionResponse.GetErrorResponse(Request.Header.TransactionType, Request.Header.TimeStamp, Request.Header.FileID, null, 'parent', '001', 'Invalid request format.');
                    requestStatus = 'Failure';
                }
                BlueStarTransactionDetails.CreateInboundTransactionRequest(Request.Header.TransactionType, Request.Header.FileID, requestStatus, reqBody, responseJSON, null, null, null, environmentCode);
            }
            catch (Exception ex) {
                System.debug('Delete Exception: ' + ex.getMessage());
                String fileId;
                if (Request.Header != null && Request.Header.FileID != null) {
                    fileId = Request.Header.FileID;
                }
                else {
                    fileId = 'Unknown';
                }
                BlueStarTransactionDetails.CreateInboundTransactionRequest(Request.Header.TransactionType, fileId, 'Exception', reqBody, ex.getMessage(), null, null, null, environmentCode);
                if(Request != null && Request.Header != null){
                  responseJSON = InboundTransactionResponse.GetErrorResponse(Request.Header.TransactionType, Request.Header.TimeStamp, Request.Header.FileID, null, 'Error', '0056', ex.getMessage());
                }else{
                    responseJSON = ex.getMessage();
                }
            }
        }
        return responseJSON;
    }
    
    public class parent {
        public String StarID {get;set;}
    }
    
    public class Header {
        public String TransactionType {get;set;}
        public String TimeStamp {get;set;}
        public String FileID {get;set;}
    }
    
    public class Request {
        public parent parent {get;set;}
        public Header Header {get;set;}
    }
    
    public class Req {
        public Request Request {get;set;}
    }
}

Thanks inadvance.
Hi Everyone,

How to write a program in apex class for delete a task object and i need to get status and see if delete task was success or not.

if anyone know please help me.thanks inadvance.

thanks,
balaji
Hi Everyone,

Can anyone please explain me how to import data from one salesforce to another salesforce without changing the id values.

Thanks inadvance
Hi Everyone,

If Anyone have idea please help me on this issue.

Here my Scenairo was we have one task page when user are creating for the sales team.How can i create a follow up time for task object and with a link of follow up date with apex controller class also.i need to get the reminder popup window notification alert before 15 mintues of due time for that user to completed the task.
In this way i dont want to use workflow r task reminders is there any different way to achieve this.if anyone have idea please help me on this issue.

thanks inadvance,
p.balu
Hi everyone,

I have one doubt.is there any specific reminder field column in salesforce.Means if i have created one task and one event after due day and dimiss all then that reminder where it will save.if any one have idea please help me.

Thanks Inadvance.
P.Balu 
Hi Everyone,

I need to know that in how many ways i can create a task popup window reminder notofications for follow up time.If anyone have idea please share with me and if possible please explain me as well.

Thanks for ur help.

thanks inadvance,
P.Balu 
Hi everyone,

Can anyone please guide my how to write a map<string> and list<string> together.please find below code and help me on this issue.

Map<String, Map<String, List<String>>> countryMap = new Map<String, Map<String, List<String>>> {'Germany' => 'German',  'Spain' => 'Spanish' ,  'France' => 'French' ,  'UnitedStates' => 'English' , 'UnitedStates' => 'Spanish' ,  'Canada' => 'English' , 'Canada' => 'French'};
            for(String c : newCountries){
                for(String l : newLanguages){
                    if(countrymap.containskey(c) && !Countrymap.get(c).contains(l)){
                        error = true;
                        account.adderror( 'country ' + c + ' does not support language ' + l);
                        return;
                    }
                }
            }

Thanks inadvance,
P.Balu
Hi everyone,

If any one have idea please guide me and explain me on these issue.

My Question was:

How Can i will  Provide unfiled public reports folder access & permission to create new reports for non-admin users.

So,please provide me and give my step by step for better understand.

Thanks Inadvance.

P.Balaji Karthik
Non static method cannot be referenced from a static context: void EmailManager.sendMail(String, String, String)
  • February 26, 2019
  • Like
  • 0