• rajubalaji
  • NEWBIE
  • 60 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 35
    Questions
  • 34
    Replies
Hi Everyone,

Is it possible to get the content of the body of any word document in apex class thorugh visual force page.Here we are trying one word document i was saved in our salesforce document list.Now i was trying to get that word document as it is by using apex class and visual force page.
Apex Class:
public class DocumentTest {
    public String content{get;set;}
    public void fetchData()
    {
        List<Folder> folderList = [Select name from Folder where name = 'Templates' Limit 1];
        if(folderList.size() > 0){
            List<Document> documentList = [SELECT name,contenttype,body from Document where folderid =:folderList[0].id and name = 'Test Form'];
            if(documentList.size() > 0){
                Blob b = documentList[0].body;
                Content = documentList.tostring();
                System.debug(Content);
            }else{
                return;
            }
        }
    }
}

Visual Force Page:
<apex:page controller="DocumentTest" contentType="application/vnd.ms-word#TestForm.doc" action="{!fetchData}">
    <apex:Form >
        <apex:pageBlock >
               <apex:outputText value="{!Content}">
                </apex:outputText>
        </apex:pageBlock>
    </apex:Form>
</apex:page>


Please anyone have idea how to read a content of word document by using apex class and visual force page.please please help me.

Thanks Inadvance,
Raju.
Hi Everyone,

I was trying one task here.one word document i was saved in our salesforce document list.Now i was trying to get that word document as it is by using apex class and visual force page.

Please anyone have idea how to read a content of word document by using apex class and visual force page.please please help me.

Thanks Inadvance,
Raju.
Hi everyone,

I was trying write a apex class for to get the content of the body of word document as what i was upload.

public void fetchData()
    {
        List<Folder> folderList = [Select name from Folder where name = 'Templates' Limit 1];
        if(folderList.size() > 0){
            List<Document> dList = [SELECT name,contenttype,body from Document where folderid =:folderList[0].id and name = 'Test_Form'];
            if(dList.size() > 0){
                content =  dList[0].body.toString();
            }
        }else{
            return;
        }
        try{
            content = content.replaceAll('@Number','5678');
            content = content.replaceAll('@Topics','Topics');
            content = content.replaceAll('@Name', 'Test');
        }catch(Exception e) 
        {
            System.debug('Exception >>> ' + e.getMessage());
        }
        
    }

But in my word document it having alot of heading and tables.Is it possible to get all content of the body.Please if anyone know if please help me.

Actually i was do sreach all links of our coummuinty still i was not getting proper information.

Thanks in Advacne,
Raju
Hi Everyone,

How to read Word Document in the Apex class.Here i was trying to write a apex class to fetch the data as shown in below code.if anyone know how to fetch data and read data please help me.

Apex Class:

public class TestFormController {
    public String comment{get;set;}
    public String content{get;set;}
    public String ContactName{get;set;}
public void fetchData()
    {
        System.debug('testForm called');
        String content;
        List<Folder> folderList = [Select id, name from Folder where name = 'Templates' Limit 1];
        if(folderList.size() > 0){
            List<Document> documentList = [SELECT id, name, body from Document where folderid =:folderList[0].id and name = 'Test Form'];
            if(documentList.size() > 0){
              content =  documentList[0].body.toString(); // while run the visual force here i was blocking mainly.
            }else{
                return;
            }
        } 
        try{
            Content = Content.replaceAll('@ContactName', 'Test');
        }catch(Exception e) 
        {
            System.debug('Exception >>> ' + e.getMessage());
        }
        
    }
}


Visual Force Page:

<apex:page contentType="application/ms-word#test Form.doc" controller="TestFormController" action="{!fetchData}">
    <apex:Form >
        <apex:pageBlock >
            <apex:outputLabel value="documentList" style="margin:0px 0 0 120px;font-size:22px;color:blue;"/>-->
            <apex:outputText value="{!content}" escape="false">
            </apex:outputText>
        </apex:pageBlock>
    </apex:Form>
</apex:page>

Please if anyone know how to fetch data please help me.

Thanks In advance,
RajuBalaji.
 
Hi everyone,

Actually we have one task,we need to Upload Document data which where in salesforce we need to get that data in other application using API"s.If any one know how to send that data please respond.

Thanks inadvance,
RajuBalaji.

Hi Everyone,

Can anyone explain to me what the use of CRM User,Sales Cloud User,Service Cloud User Permission Set licesne while given to users?

Thanks,

RajuBalaji
 

HI Everyone,

I was writing test class for batch apex i was written all ways but still i was in 18% code coveagre if anyone help me to reach 100% coverage.

Batch Apex:

public class UserRegistrationStatusUpdate implements Database.Batchable<sObject> {
    
    public UserRegistrationStatusUpdate() {}

    public Database.QueryLocator start(Database.BatchableContext BC) {
        System.debug('UserRegistrationStatusUpdate start');
        if (Label.User_RegistrationCheck_TimeInHours == '-1') {
            return Database.getQueryLocator([Select Id, AccountID__c, Email__c, External_Parent_Id__c from Hub_Parent__c Where Product_Status__c = 'Active' and Registration_Completed_Date__c != null]);
        }
        else {
            Datetime registrationStartDay = Datetime.now().addHours(-Integer.valueOf(Label.user_RegistrationCheck_TimeInHours));
            return Database.getQueryLocator([Select Id, AccountID__c, Email__c, External_Parent_Id__c from Hub_Parent__c Where Product_Status__c = 'Active' and Registration_Completed_Date__c != null and Registration_Completed_Date__c >= :registrationStartDay]);
        }
    }
    
    public void execute(Database.BatchableContext BC, List<Hub_Parent__c> ParentList) {
        try {
            System.debug('userRegistrationStatusUpdate execute count ' + ParentList.size());
            List<user__c> userToUpdateList = new List<user__c>();
            List<user__c> userList;
            String emailHashed;
            String memberIDHashed;
            Blob b;
            for (Hub_Parent__c Parent : ParentList) {
                b = Crypto.generateDigest('SHA-256', Blob.valueOf(Parent.Email__c.toLowerCase()));
                emailHashed = EncodingUtil.base64Encode(b);
                
                userList = [Select Id, Registered_User__c from user__c Where AccountID__c = :Parent.AccountID__c and Eligibility_User__c = false and EmailHashed__c = :emailHashed Limit 1];
                if (userList.size() > 0) {
                    if (userList[0].Registered_User__c == false) {
                        userList[0].Registered_User__c = true;
                        userToUpdateList.add(userList[0]);
                    }
                }
                else {
                    if (Parent.External_Parent_Id__c != null) {
                        b = Crypto.generateDigest('SHA-256', Blob.valueOf(Parent.External_Parent_Id__c.toLowerCase()));
                        memberIDHashed = EncodingUtil.base64Encode(b);
                        userList = [Select Id, Registered_User__c from user__c Where AccountID__c = :Parent.AccountID__c and Eligibility_User__c = false and Registered_User__c = false and MemberIDHashed__c = :memberIDHashed Limit 1];
                        if (userList.size() > 0) {
                            userList[0].Registered_User__c = true;
                            userToUpdateList.add(userList[0]);
                        }
                    }
                }
            }
            if (userToUpdateList.size() > 0) {
                update userToUpdateList;
            }
        } catch (Exception ex) {
            System.debug('userRegistrationStatusUpdate Exception :' + ex.getMessage());
        }
    }
    
    public void finish(Database.BatchableContext BC) {}
}

Test Class for above Batch Apex:

@isTest
public class UserRegistrationStatusUpdateTest {
    static testMethod void testUserRegistrationStatusUpdate(){
        
        Test.startTest();
        
        TestController.createCustomSettings();
        TestController.createEnviornmentSettings();
        Hub_Parent__c pt = TestController.getMockParentObject();
        List<User__c> User = new List<User__c>();
        User__c U= new User__c();
        U.FirstName__c = 'nMM';
        U.LastName__c = 'MMM';
        U.Gender__c = 'Male';
        U.Email__c = pt.Email__c;
        Blob b = Crypto.generateDigest('SHA-256', Blob.valueOf(U.Email__c.toLowerCase()));
        U.EmailHashed__c = EncodingUtil.base64Encode(b);
        U.DOB__c = system.today();
        U.Member_ID__c = '10755633045998625107';
        Blob b1 = Crypto.generateDigest('SHA-256', Blob.valueOf(U.Member_ID__c.toLowerCase()));
        U.MemberIDHashed__c = EncodingUtil.base64Encode(b1);
        U.AccountID__c = pt.AccountID__c;
        
        insert U;
        
        
        UserRegistrationStatusUpdate obj = new UserRegistrationStatusUpdate();
        DataBase.executeBatch(obj);
        
        Test.stopTest();
    }
}

Thanks InAdvance.
Hi Everyone,

How to add Users at connected app?

If anyone know please please try to help me.

Thanks inadvance.
Hi Everyone,

I was very new the pardot topic.i was went through the salesfroce trailbalizer and so many links also.

My question is:

1) Whether pardot will support in only lightning app or it will support in classic as well.
2) if it was support only in lightning which ever customization we done at lightning it will reflects in classic also.


i am very thankful to everyone.if anyone have idea please give me reply.

thank you once again.

Thanks,
RajuBalaji.
Hi Team,

Anyone was have idea about how write a test class for below code.if knows please help me out.

public with sharing class ParentexampleController {    
    public Example Example{get;set;}
    public ActivityData activityData{get;set;}
    public Device deviceInfo{get;set;}
    public MGCDeviceInf MGCDeviceInfo{get;set;}

        List<Example> lstExample = [Select ID from Example where parentid__c=:parentid];
            if (lstExample != null && lstExample.size() > 0) {
                delete lstExample;
            }
            
            List<Activity_Tracker_Information__c> lstActivityTrackerInfo = [Select ID from Activity_Tracker_Information__c where parentid__c=:parentid];
            if (lstActivityTrackerInfo != null && lstActivityTrackerInfo.size() > 0) {
                delete lstActivityTrackerInfo;
            }
            
            Example Example = new Example();
            Example.parentid__c = parentid;
            Example.ReadingLatestDate__c = Example.ReadingLatestDate;
            Example.ReadingLatestDate__c = Example.ReadingLatestDate;
            insert Example;
            
            if (obj.activityTrackerData != null && obj.activityTrackerData.Name != null) {
                List<Activity_Tracker_Information__c> lstActivityTracker = new List<Activity_Tracker_Information__c>();
                Activity_Tracker_Information__c activity = new Activity_Tracker_Information__c();
                activity.parentid__c = parentid;
                activity.Name__c = activityTrackerData.Name;
                activity.Last_Sync_Date__c = activityTrackerData.CreatedDateTime;
                lstActivityTracker.add(activity);
                insert lstActivityTracker;
            }
            
            if (obj.MGCDeviceInfo != null && obj.MGCDeviceInfo.Status != null) {
                if (obj.MGCDeviceInfo.Status == 1) {
                    MGCDeviceInfo.StatusDescription = 'Active';
                }
                else if (obj.MGCDeviceInfo.Status == 2) {
                    MGCDeviceInfo.StatusDescription = 'InActive';
                }
            }
}catch (System.NullPointerException e){
            System.debug('The following exception has occurred: ' + e.getMessage());
        }
    }
    
    public class ParentRequestData{
        public String StarID {get;set;}
        public String parentid {get;set;}
    }


Thanks inadvance,
Raju.
Hi Everyone

Anyone have idea please help me guide for test class for catch (Exception ex) below code:

catch (Exception ex) {
                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(), parentId, null, null, environmentCode);
                if(Request != null && Request.Header != null){
                    responseJSON = InboundTransactionResponse.GetErrorResponse(Request.Header.TransactionType, Request.Header.TimeStamp, Request.Header.FileID, null, 'Error', '0036', ex.getMessage());
                }else{
                    responseJSON = ex.getMessage();
                }

Please anyone know about that please help me.

Thanks,
Raju
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,

Actually we have one task,we need to Upload Document data which where in salesforce we need to get that data in other application using API"s.If any one know how to send that data please respond.

Thanks inadvance,
RajuBalaji.
Hi Everyone,

Is it possible to get the content of the body of any word document in apex class thorugh visual force page.Here we are trying one word document i was saved in our salesforce document list.Now i was trying to get that word document as it is by using apex class and visual force page.
Apex Class:
public class DocumentTest {
    public String content{get;set;}
    public void fetchData()
    {
        List<Folder> folderList = [Select name from Folder where name = 'Templates' Limit 1];
        if(folderList.size() > 0){
            List<Document> documentList = [SELECT name,contenttype,body from Document where folderid =:folderList[0].id and name = 'Test Form'];
            if(documentList.size() > 0){
                Blob b = documentList[0].body;
                Content = documentList.tostring();
                System.debug(Content);
            }else{
                return;
            }
        }
    }
}

Visual Force Page:
<apex:page controller="DocumentTest" contentType="application/vnd.ms-word#TestForm.doc" action="{!fetchData}">
    <apex:Form >
        <apex:pageBlock >
               <apex:outputText value="{!Content}">
                </apex:outputText>
        </apex:pageBlock>
    </apex:Form>
</apex:page>


Please anyone have idea how to read a content of word document by using apex class and visual force page.please please help me.

Thanks Inadvance,
Raju.
Hi everyone,

I was trying write a apex class for to get the content of the body of word document as what i was upload.

public void fetchData()
    {
        List<Folder> folderList = [Select name from Folder where name = 'Templates' Limit 1];
        if(folderList.size() > 0){
            List<Document> dList = [SELECT name,contenttype,body from Document where folderid =:folderList[0].id and name = 'Test_Form'];
            if(dList.size() > 0){
                content =  dList[0].body.toString();
            }
        }else{
            return;
        }
        try{
            content = content.replaceAll('@Number','5678');
            content = content.replaceAll('@Topics','Topics');
            content = content.replaceAll('@Name', 'Test');
        }catch(Exception e) 
        {
            System.debug('Exception >>> ' + e.getMessage());
        }
        
    }

But in my word document it having alot of heading and tables.Is it possible to get all content of the body.Please if anyone know if please help me.

Actually i was do sreach all links of our coummuinty still i was not getting proper information.

Thanks in Advacne,
Raju
Hi Everyone,

How to add Users at connected app?

If anyone know please please try to help me.

Thanks inadvance.
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