You need to sign in to do that
Don't have an account?

test class code
I want the test class code. Can anyone suggest me with the test class code for the apex code.
public with sharing class TextMessage { List<text__c> appTextMessage = [select text_message__c FROM text__c ]; Map<ID, Contact> contactMap = new Map<ID, Contact>([select id, firstname from contact]); List<String> displayMessage = new List<String>(); public List<String> messageTemplate() { for (text__c textMessage : appTextMessage) { String text = textMessage.text_message__c; if(text !=null ){ Set<ID> keyId = contactMap.keySet(); for(ID c :keyId){ displayMessage.add(contactMap.get(c).firstname + ' ' + text + '\n'); System.debug(displayMessage); } } } return displayMessage; } }
Thanks in advance.
@isTest
private class TestTextMessage {
static testmethod void TestmessageTemplate(){
test.startTest();
Account acc=new Account();
acc.Name = 'My Account';
insert acc;
Contact con=new Contact();
con.AccountId=acc.id;
con.firstname='Robin';
con.LastName='Hood';
insert con;
List<String> sResult=TextMessage.messageTemplate();
system.assertNotEqulas(sResult,null);
test.stopTest();
}
}
Here you go :
But let me tell you one thing, the logic implemented is not correct as you are using for in for and if there are 1K records in both object then you will get too many script statements for sure. For now the test will work. I will suggest you to refactor your code or just apply limits in the query.
Thanks
Ankit Arora
Blog | Facebook | Blog Page
Cross post, but please do as I suggested. Else you will face error when there are too many records in organization.
Thanks
Ankit Arora
Blog | Facebook | Blog Page
Please let me know if there is any issue.
Welcome Devendra, you are also included in the list of cross post :)
Thanks
Ankit Arora
Blog | Facebook | Blog Page