-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
18Questions
-
15Replies
How to convert createdDateTime value Into Timevalue
Hi All,
I have a requirment in my project. I need convert CreatedDate value Into Custom field Timevalue using apex . I want only Time value not date. And Time values should be in 24 hour format such like that 14:00 of 2:00 PM . If anyone use these type functionality in your project please guide me.
Thanks & Regards
Sebastian Page
I have a requirment in my project. I need convert CreatedDate value Into Custom field Timevalue using apex . I want only Time value not date. And Time values should be in 24 hour format such like that 14:00 of 2:00 PM . If anyone use these type functionality in your project please guide me.
Thanks & Regards
Sebastian Page
- Sebastian Page
- April 08, 2021
- Like
- 0
How can be extract all picklist values Using apex
I have a requirment to fetch the details of a record type (case Object) and present in JSON.
Among other fields on the Record type, there are few dependent Picklist fields :
Ticket Category (Controlling Ticket Type)
Ticket Type (controlling Ticket Item)
Ticket Item
I am suppose to extract all the mappings of the picklists and fields on the record type page layout.
If some one have worked on a similar requirement, please suggest how this can be achieved.
Thanks and Regards
Sebastian Page
Among other fields on the Record type, there are few dependent Picklist fields :
Ticket Category (Controlling Ticket Type)
Ticket Type (controlling Ticket Item)
Ticket Item
I am suppose to extract all the mappings of the picklists and fields on the record type page layout.
If some one have worked on a similar requirement, please suggest how this can be achieved.
Thanks and Regards
Sebastian Page
- Sebastian Page
- March 18, 2021
- Like
- 0
I am not getting code coverage showing error
Hi Expert ,
I am updating contact field from user object using schedule class. and My apex class working fine but I am getting error while test class running and also i am not getting code coverage. kindly assist me where i am doing mistake.
Error is showing - "System.DmlException: Insert failed. First exception on row 0 with id 0011F00000oLXWlQAO; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]".
and My Test class is
I am updating contact field from user object using schedule class. and My apex class working fine but I am getting error while test class running and also i am not getting code coverage. kindly assist me where i am doing mistake.
Error is showing - "System.DmlException: Insert failed. First exception on row 0 with id 0011F00000oLXWlQAO; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]".
public class Global_UserLastLoginController implements Schedulable{ public void execute(SchedulableContext SC) { Global_UserLastLoginController.getLastLogin(); // Global_UserLastLoginController.getUpdateLicence(); } public static void getLastLogin() { List<Contact> getupdateContact=new List<contact>(); Map<String,Datetime> mapcontact= new Map<String,Datetime>(); List<User> getUserLst=[select Contactid,lastLoginDate from user where contactId!=null and isactive=true and AccountId='0011F00000ml9jh']; for(User u:getUserLst) { mapcontact.put(u.ContactId, u.lastLoginDate); } for(Contact con:[select id,Last_Login__c from contact where accountId='0011F00000ml9jh']) { con.Last_Login__c=mapcontact.get(con.id); getupdateContact.add(con); } update getupdateContact; } }
and My Test class is
@isTest public class Global_UserLastLoginUpdateTest { @isTest public Static void UnitlastLoginTest() { String CRON_EXP = '0 15 * * * ?'; Test.startTest(); Account acc=new Account(); acc.name='Pasadena'; insert acc; acc.Enable_CaseCreationTrigger__c=true; acc.Account_Case_RecType_Validation__c='Pasadena'; insert acc; system.assertEquals(True, acc.Enable_CaseCreationTrigger__c); Contact con = new Contact(AccountId=acc.Id,LastName='test'); insert con; String jobId = System.schedule('Global_UserLastLoginUpdateTest', CRON_EXP, new Global_UserLastLoginController()); CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :jobId]; System.assertEquals(CRON_EXP, ct.CronExpression); System.assertEquals(0, ct.TimesTriggered); test.stopTest(); } }
- Sebastian Page
- February 04, 2021
- Like
- 0
Why Some lines of apex trigger is not covered code coverage
Hi Expert,
I have business requirment for Case merge. Whenever Case (ticket) is creating by Email Case and Ticket is duplicate. then Case (ticket ) status should be change closed sucessful (duplicate). And all comments and attachemts will be add into parrent ticket.
my apex trigger working smoothly as per requirment but when i create test class i got 48 % code coverage. Please assist me where is mistak.
I am adding Screen shoot where i getting code covering problem.
Here my apex trigger-
And this is a test class
I have business requirment for Case merge. Whenever Case (ticket) is creating by Email Case and Ticket is duplicate. then Case (ticket ) status should be change closed sucessful (duplicate). And all comments and attachemts will be add into parrent ticket.
my apex trigger working smoothly as per requirment but when i create test class i got 48 % code coverage. Please assist me where is mistak.
I am adding Screen shoot where i getting code covering problem.
Here my apex trigger-
trigger EMailToCaseMerge on Case (After insert) { List<string> lstSubject=new List<String>(); Set<Id>AccId =new Set<Id>(); Set<Id>RecId = new Set<Id>(); String casId=''; List<String> dupCas=new List<String>(); list<String> getuserId =CaseMergeEmail.getuserIdlst(); system.debug('userIds'+getuserId); List<Case> lstUpdateCase= new list<case>(); for(Trigger_Control__c tc:Trigger_Control__c.getall().values()){ if(tc.Enable_zGlobalCaseMerge__c==true) { for(Case cs :Trigger.new) { AccId.add(cs.AccountId); lstSubject.add(cs.Subject); RecId.add(cs.recordTypeId); } if(userInfo.getUserName()=='administrator@helpdesk.org.newapi'){ List<Case> getCaslst=[select status,parentId, Prevent_Closure_Email__c,Prevent_CaseComment_Notification__c,id from case where accountId in:AccId and subject in:lstSubject and isClosed=false and recordtypeId in:RecId and status!='Escalated' order by createddate]; if(getCaslst.size()>0){ system.debug('getCaslst[0].id'+getCaslst[0].id); casId=getCaslst[0].id; for(Case cs:getCaslst) { if(cs.id!=getCaslst[0].id) { cs.parentId=getCaslst[0].id; cs.Prevent_Closure_Email__c=true; cs.Prevent_CaseComment_Notification__c=true; cs.status='Closed (Duplicate)'; lstUpdateCase.add(cs); dupCas.add(cs.Id); } } update lstUpdateCase; if(dupCas.size()>0) { CaseMergeEmail.casAttachment(dupCas,casId); CaseMergeEmail.CasCommnet(dupCas,casId); // CaseMergeEmail.TicketLogs(trigger.new,casId); } } } } } }
And this is a test class
@IsTest public class CaseMergeHandlerTest { static testMethod void testMerge(){ List<String>DupCase =new List<String>(); Account testAccount = new Account(Name='Test Company Name123'); insert testAccount; Contact con = new Contact(LastName='Testcont' ,Email='sss@test.com', AccountId=testAccount.Id); insert con; Trigger_Control__c tc=new Trigger_Control__c(); tc.name='testCustumer'; tc.Enable_zGlobalCaseMerge__c=true; insert tc; User u; User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()]; System.runAs (thisUser) { Profile p = [SELECT Id FROM Profile WHERE Name='CH_Tier1-Partner']; u = new User(alias = 'tstwy', email='testmail@tst.com', emailencodingkey='UTF-8', lastname='testL', languagelocalekey='en_US', localesidkey='en_US', profileid = p.Id, ContactId = con.Id, timezonesidkey='America/Los_Angeles', username='testmailxxx@tst.com'); insert u; } System.runAs (u) { List<RecordType> listRecType = [select Id from RecordType where sObjectType = 'Case' And Name = 'Pasadena_Ticket']; List<Case>lstcase =new List<Case>(); for(Integer i=0; i <2; i++){ lstcase.add(new Case( Prevent_Closure_Email__c=true,Prevent_CaseComment_Notification__c=true,AccountId=testAccount.Id, ContactId = con.Id,Origin='Email', subject='test',recordtypeId= listRecType[0].Id ,Status='New',ownerid='00Gd0000001QYQU')); } insert lstcase; DupCase.add(lstcase[0].Id); DupCase.add(lstcase[1].Id); Attachment attach=new Attachment(); attach.Name='test.html'; Blob bodyBlob=Blob.valueOf('Unit Test Attachment Body'); attach.Body=bodyBlob; attach.ParentId=lstcase[0].Id; insert attach; List<Attachment> attachments=[SELECT Id, Name, ParentId FROM Attachment WHERE Parent.Id=:lstcase[0].Id]; System.assertEquals(1, attachments.size()); //Sanity check caseComment newcmt=new casecomment(); newcmt.ParentId=lstcase[0].Id; newcmt.CommentBody='Test comments'; insert newcmt; List<caseComment> lstCaseComments=[SELECT Id, CommentBody, ParentId FROM caseComment WHERE Parent.Id=:lstcase[0].Id limit 1]; System.assertEquals(1, lstCaseComments.size()); //Sanity check*/ Test.startTest(); CaseMergeEmail.casAttachment(DupCase, lstcase[0].Id); CaseMergeEmail.CasCommnet(DupCase, lstcase[0].Id); //CaseMergeEmail.TicketLogs(lstcase); Test.stopTest(); attachments=[SELECT Id, Name, ParentId FROM Attachment WHERE Parent.Id=:lstcase[0].Id]; System.assertEquals(2, attachments.size()); //real check - did we duplicate the attachment System.assertEquals(attachments[0].Name, attachments[1].Name); lstCaseComments=[SELECT Id, CommentBody,ParentId FROM CaseComment WHERE Parent.Id=:lstcase[0].Id]; System.assertEquals(2, lstCaseComments.size()); System.assertEquals(lstCaseComments[0].CommentBody, lstCaseComments[1].CommentBody); } } }
- Sebastian Page
- January 06, 2021
- Like
- 0
Why Some line of the code is not covering
Hi All
Why Some line is not covering code coverage .
I am using test class here
@isTest
public class CaseMergeHandlerTest {
static testMethod void testMerge(){
List<String>DupCase =new List<string>();
Account testAccount = new Account(Name='Test Company Name123');
insert testAccount;
Contact con = new Contact(LastName='Testcont' ,Email='sss@test.com', AccountId=testAccount.id);
insert con;
list<case>lstcase =new LIst<case>();
Case caseObj1 = new Case();
caseObj1.AccountId = testAccount.Id;
caseObj1.contactId=con.id;
caseObj1.Status = 'Action-Automated Escalation';
caseObj1.Origin ='Email';
lstcase.add(caseObj1);
DupCase.add(caseObj1.id);
Case caseObj2 = new Case();
caseObj2.AccountId = testAccount.Id;
caseObj2.contactId=con.id;
caseObj2.Status = 'Closed Duplicate';
caseObj2.Origin ='Email';
lstcase.add(caseObj2);
DupCase.add(caseObj2.id);
test.startTest();
insert lstcase;
attachment attach=new attachment();
attach.name='test.html';
Blob bodyBlob=Blob.valueOf('Unit Test Attachment Body');
attach.body=bodyBlob;
attach.parentId=lstcase[0].id;
insert attach;
List<Attachment> attachments=[select id, name from Attachment where parent.id=:lstcase[0].id];
System.assertEquals(1, attachments.size());
CaseMergeEmail.casAttachment(DupCase, caseObj1.id);
CaseMergeEmail.CasCommnet(DupCase, caseObj1.id);
test.stopTest();
}
}
Please help on this issue.
- Sebastian Page
- September 17, 2020
- Like
- 0
Need help on Aura Lightning controller
Hello Expert,
I have created aura lightning component where we display how many Cases are open.Here we are displaying cases summery in the three coloumns.
1. Owned by me 2.Owner Name 3. cases
I have requirment if there is no ticket assiged to me or my queues than i want aprear one popup measseg on the div.
This is my Controller method. please help me.
I have created aura lightning component where we display how many Cases are open.Here we are displaying cases summery in the three coloumns.
1. Owned by me 2.Owner Name 3. cases
I have requirment if there is no ticket assiged to me or my queues than i want aprear one popup measseg on the div.
This is my Controller method. please help me.
action.setCallback(this, function(response) { //store state of response var state = response.getState(); if (state === "SUCCESS") { //set response value in wrapperList attribute on component. component.set("v.lstCases", response.getReturnValue()); if(response.getReturnValue()>0) component.set("v.flag","display:block"); else component.set("v.flag","display:none");
- Sebastian Page
- June 10, 2020
- Like
- 0
Redirect link is not working in lightning component
Hello Experts,
I am working on developing a lightning app where I have to display open tickets where the running user is owner of the ticket or he is a member of queue to which he is a member.
I am able to display the list of cases but I can not make it clickable on the link / button. Here it is expected to open the ticket in a new browser TAB.
Error : Page does not exist's
If any one have worked on similar requirement, I would appriciate any suggestions as what I am missing to make it work. My Controller logic appers as follows:
dohandelClick : function(component, event, helper){ var eventSource=event.getSource(); var Id=eventSource.get('v.name'); var navEvt = $A.get("e.force:navigateToSObject"); navEvt.setParams({ "recordId": Id }); navEvt.fire(); }
Component defination
<div class="slds-truncate" title="Cloudhub"> <lightning:button name="{!cs.id}" variant="brand" label="Vew Detail" onclick="{!c.dohandelClick}" /> </div>
Thanks,
Sebastian.
- Sebastian Page
- January 13, 2020
- Like
- 0
problem in test class i can't understand why is happening we got only 33 % code coverage
trigger SpamControllerTrigger on Case (before insert) { /*===================================================hhjjf====================================*/ List<String> lstBasedOnDesc=new List<String>(); for(Keywords__c ks:[Select name from Keywords__c]) { lstBasedOnDesc.add(ks.name); } List<String>LstSpamkeyword=new List<String>(); /*===================================================hhjjf====================================*/ for(Trigger_Control__c tc:Trigger_Control__c.getAll().values()) { if( tc.Enable_Spam_Controller_Trigger__c==true) { for(case cs:Trigger.new) { if(userinfo.getName()=='Automated Workflow') { if(lstBasedOnDesc.size()>0) { for(String s:lstBasedOnDesc) { if(cs.Description!=null && ( cs.Description).Contains(s)) { cs.ownerId='00Gd00000027kH7'; cs.Spam_criteria__c='Based on Description'; cs.Possible_Spam__c=true; cs.Identified_Keyword__c=s; } else if(cs.Subject!=null && (cs.Subject).Contains(s)) { cs.ownerId='00Gd00000027kH7';cs.Spam_criteria__c='Based on Subject'; cs.Possible_Spam__c=true;cs.Identified_Keyword__c=s; } else if((cs.SuppliedEmail).Contains(s)) { cs.ownerId='00Gd00000027kH7'; cs.Spam_criteria__c='Based on Webmail'; cs.Possible_Spam__c=true; cs.Identified_Keyword__c=s; } if(cs.Subject==null || cs.Description==null) { cs.ownerId='00Gd00000027kH7'; cs.Spam_criteria__c='Blank Description / Subject'; cs.Possible_Spam__c=true; cs.Identified_Keyword__c='Blank Subject or Description'; } } } } } } } }Hi All,
We are getting only 33% code coverage . And rest of lines is showing in red color that not cover.
my test class is here-
@isTest public class SpamControllerTriggerTest { @isTest public Static void SpamTestmethod() { Profile pf = [SELECT Id FROM Profile WHERE Name = 'System Administrator']; User tuser = new User(lastName = 'Automated Workflow', email = 'AutomatedWorkflow@test.org', Username = 'AutomatedWorkflow@test123.org', EmailEncodingKey = 'ISO-8859-1', Alias = 'AW', TimeZoneSidKey = 'America/Los_Angeles', LocaleSidKey = 'en_US', LanguageLocaleKey = 'en_US', ProfileId = pf.Id); insert tuser; system.runAs(tuser){ Account acc = new Account(Name='MassBay'); insert acc; Contact con = new Contact(AccountId=acc.Id,LastName='test',Email='desd.red@test.tst'); insert con; Trigger_Control__c tc=new Trigger_Control__c(); tc.Enable_Spam_Controller_Trigger__c=true; tc.Name='test tc'; insert tc; List<case>lstcase=new List<case>(); List<RecordType> listRecType = [select Id from RecordType where sObjectType = 'Case' And Name = 'MassBayCC_Ticket']; Case cs = new Case(RecordTypeId = listRecType[0].Id,AccountId=acc.Id,ContactId=con.Id); cs.Spam_criteria__c='Based on Description'; cs.Subject='tesr'; cs.Description='Test Description1'; cs.SuppliedEmail='shr.jdd@test.com'; cs.Possible_Spam__c=true; cs.Identified_Keyword__c='s'; lstcase.add(cs); Case cs1 = new Case(RecordTypeId = listRecType[0].Id,AccountId=acc.Id,ContactId=con.Id); cs1.Spam_criteria__c='Based on Webmail'; cs1.Subject='tesr'; cs1.Description='Test Description 2'; cs1.SuppliedEmail='shr.jdd@test.com'; cs1.Possible_Spam__c=true; cs1.Identified_Keyword__c='s'; lstcase.add(cs1); Case cs2 = new Case(RecordTypeId = listRecType[0].Id,AccountId=acc.Id,ContactId=con.Id); cs2.Spam_criteria__c='Based on Subject'; cs2.Subject='tesr'; cs2.Description='Test Description 3'; cs2.SuppliedEmail='shr.jdd@test.com'; cs2.Possible_Spam__c=true; cs2.Identified_Keyword__c='s'; lstcase.add(cs2); insert lstcase; } } }
- Sebastian Page
- January 08, 2020
- Like
- 0
problem in test code i have got 13 percent code coverage
Hi All,
I am facing issue of our test class we only got 13 perent code coverage please help
me
trigger autoCreateContactController on Case (before insert) {
for(Trigger_Control__c tc:Trigger_Control__c.getAll().values())
{
if( tc.Enable_Auto_Create_contact_Trigger__c==true)
{
for(case cs:trigger.new)
{
if(userinfo.getName()=='Automated Workflow'){
contact[] lstcontact= [select id from contact where email=:cs.SuppliedEmail limit 1];
if(!lstcontact.isEmpty())
{
String contId=lstcontact[0].id;
if(contId!=null)
{
cs.ContactId=contId;
}
}
else {
String leftPart = cs.Suppliedname;
String[] leftPartSplitted = leftPart.split('\\s+');
if(leftPart!=null || leftPart!='')
{
if(leftPartSplitted.size() == 3)
{
String firstName = leftPartSplitted[0];
String lastName = leftPartSplitted[1];
String middlename=leftPartSplitted[2];
contact con1 =new contact();
con1.firstname=firstName;
con1.LastName=lastName+middlename;
con1.Email=cs.SuppliedEmail;
con1.AccountId='0010W00002MuDcQQAV';
insert con1;
cs.ContactId=con1.Id;
}
else if(leftPartSplitted.size() == 2)
{
String firstName = leftPartSplitted[0];
String lastName = leftPartSplitted[1];
contact con1 =new contact();
con1.firstname=firstName;
con1.LastName=lastName;
con1.Email=cs.SuppliedEmail;
con1.AccountId='0010W00002MuDcQQAV';
insert con1;
cs.ContactId=con1.Id;
}
else if(leftPartSplitted.size() == 1)
{
String lastName = leftPartSplitted[0];
contact con1 =new contact();
con1.LastName=lastName;
con1.Email=cs.SuppliedEmail;
con1.AccountId='0010W00002MuDcQQAV';
insert con1;
cs.ContactId=con1.Id;
}
}
}
}}}
}}
My test class is
@isTest
public class AutoCreateContactControllerTest {
@isTest
public Static void SpamTestmethod()
{ Account acc = new Account(Name='MassBay');
insert acc;
Contact con = new Contact(AccountId=acc.Id,LastName='test',Email='tttt@test.com');
insert con;
Trigger_Control__c tc=new Trigger_Control__c();
tc.Enable_Auto_Create_contact_Trigger__c=true;
tc.Name='test tc';
insert tc;
List<case>lstcase=new List<case>();
List<RecordType> listRecType = [select Id from RecordType where sObjectType = 'Case' And Name = 'MassBayCC_Ticket'];
Case cs = new Case(RecordTypeId = listRecType[0].Id,AccountId=acc.Id,ContactId=con.Id);
cs.Subject='tesr';
cs.Description='Test description';
cs.SuppliedEmail='tttt@test.com';
cs.SuppliedName='hello world';
lstcase.add(cs);
Case cs1 = new Case(RecordTypeId = listRecType[0].Id,AccountId=acc.Id,ContactId=con.Id);
cs1.Subject='tesr';
cs1.Description='Test Description';
cs1.SuppliedEmail='tttt@test.com';
cs1.SuppliedName='hello world world';
lstcase.add(cs1);
Case cs2 = new Case(RecordTypeId = listRecType[0].Id,AccountId=acc.Id,ContactId=con.Id);
cs2.Subject='tesr';
cs2.Description='Test Description';
cs2.SuppliedEmail='tttt@test.com';
cs2.SuppliedName='hello';
lstcase.add(cs2);
insert lstcase;
}
}
I am facing issue of our test class we only got 13 perent code coverage please help
me
trigger autoCreateContactController on Case (before insert) {
for(Trigger_Control__c tc:Trigger_Control__c.getAll().values())
{
if( tc.Enable_Auto_Create_contact_Trigger__c==true)
{
for(case cs:trigger.new)
{
if(userinfo.getName()=='Automated Workflow'){
contact[] lstcontact= [select id from contact where email=:cs.SuppliedEmail limit 1];
if(!lstcontact.isEmpty())
{
String contId=lstcontact[0].id;
if(contId!=null)
{
cs.ContactId=contId;
}
}
else {
String leftPart = cs.Suppliedname;
String[] leftPartSplitted = leftPart.split('\\s+');
if(leftPart!=null || leftPart!='')
{
if(leftPartSplitted.size() == 3)
{
String firstName = leftPartSplitted[0];
String lastName = leftPartSplitted[1];
String middlename=leftPartSplitted[2];
contact con1 =new contact();
con1.firstname=firstName;
con1.LastName=lastName+middlename;
con1.Email=cs.SuppliedEmail;
con1.AccountId='0010W00002MuDcQQAV';
insert con1;
cs.ContactId=con1.Id;
}
else if(leftPartSplitted.size() == 2)
{
String firstName = leftPartSplitted[0];
String lastName = leftPartSplitted[1];
contact con1 =new contact();
con1.firstname=firstName;
con1.LastName=lastName;
con1.Email=cs.SuppliedEmail;
con1.AccountId='0010W00002MuDcQQAV';
insert con1;
cs.ContactId=con1.Id;
}
else if(leftPartSplitted.size() == 1)
{
String lastName = leftPartSplitted[0];
contact con1 =new contact();
con1.LastName=lastName;
con1.Email=cs.SuppliedEmail;
con1.AccountId='0010W00002MuDcQQAV';
insert con1;
cs.ContactId=con1.Id;
}
}
}
}}}
}}
My test class is
@isTest
public class AutoCreateContactControllerTest {
@isTest
public Static void SpamTestmethod()
{ Account acc = new Account(Name='MassBay');
insert acc;
Contact con = new Contact(AccountId=acc.Id,LastName='test',Email='tttt@test.com');
insert con;
Trigger_Control__c tc=new Trigger_Control__c();
tc.Enable_Auto_Create_contact_Trigger__c=true;
tc.Name='test tc';
insert tc;
List<case>lstcase=new List<case>();
List<RecordType> listRecType = [select Id from RecordType where sObjectType = 'Case' And Name = 'MassBayCC_Ticket'];
Case cs = new Case(RecordTypeId = listRecType[0].Id,AccountId=acc.Id,ContactId=con.Id);
cs.Subject='tesr';
cs.Description='Test description';
cs.SuppliedEmail='tttt@test.com';
cs.SuppliedName='hello world';
lstcase.add(cs);
Case cs1 = new Case(RecordTypeId = listRecType[0].Id,AccountId=acc.Id,ContactId=con.Id);
cs1.Subject='tesr';
cs1.Description='Test Description';
cs1.SuppliedEmail='tttt@test.com';
cs1.SuppliedName='hello world world';
lstcase.add(cs1);
Case cs2 = new Case(RecordTypeId = listRecType[0].Id,AccountId=acc.Id,ContactId=con.Id);
cs2.Subject='tesr';
cs2.Description='Test Description';
cs2.SuppliedEmail='tttt@test.com';
cs2.SuppliedName='hello';
lstcase.add(cs2);
insert lstcase;
}
}
- Sebastian Page
- January 08, 2020
- Like
- 0
code coverage not increasing in my apex trigger
Hi all,
code coverage not increasing in my apex trigger please help me
my apex code is
trigger autoCreateContactController on Case (before insert) {
for(case cs:Trigger.new)
{
if(lstBasedOnDesc.size()>0)
{
for(String s:lstBasedOnDesc)
{
if((cs.SuppliedEmail).Contains(s))
{
cs.ownerId='00Gd00000027kH7';
}
else {
List<contact> lstcontact= [select id from contact where email=:cs.SuppliedEmail limit 1];
if(lstcontact.size()>0)
{
cs.ContactId=lstcontact.get(0).id;
}
else{
String leftPart = cs.SuppliedEmail.substringBefore('@');
if(leftPart.contains('.')){
String[] leftPartSplitted = leftPart.split('\\.');
//we check if there's one dot in the substring
if(leftPartSplitted.size() == 2 ){
String firstName = leftPartSplitted[0];
String lastName = leftPartSplitted[1];
contact con1 =new contact();
con1.firstname=firstName;
con1.LastName=lastName;
con1.Email=cs.SuppliedEmail;
con1.AccountId='0010W00002MuDcQ';
insert con1;
cs.ContactId=con1.Id;
}
}
else if(leftPart.contains('_')){
String[] leftPartSplitted = leftPart.split('\\_');
if(leftPartSplitted.size()==2)
{
String firstName = leftPartSplitted[0];
String lastName = leftPartSplitted[1];
contact con1 =new contact();
con1.firstname=firstName;
con1.LastName=lastName;
con1.Email=cs.SuppliedEmail;
con1.AccountId='0010W00002MuDcQ';
insert con1;
cs.ContactId=con1.Id;
}
}
else{
String firstName = 'unkown';
String lastName = leftPart;
contact con1 =new contact();
con1.firstname=firstName;
con1.LastName=lastName;
con1.Email=cs.SuppliedEmail;
con1.AccountId='0010W00002MuDcQ';
insert con1;
cs.ContactId=con1.Id;
}}}}}}
and my test class is
@isTest
public class AutoCreateContactControllerTest {
@isTest
public Static void SpamTestmethod()
{ Account acc = new Account(Name='test11');
insert acc;
Contact con = new Contact(AccountId=acc.Id,LastName='test',Email='desd.red@test.tst');
insert con;
Trigger_Control__c tc=new Trigger_Control__c();
tc.Enable_Spam_Controller_Trigger__c=true;
tc.Name='test tc';
insert tc;
User u;
User thisUser = [SELECT Id FROM User WHERE Id = '005d000000187CwAAI'];
System.runAs (thisUser) {
Profile p = [SELECT Id FROM Profile WHERE Name='CH_Tier1-Partner'];
u = new User(alias = 'tstwy', email='testmail@tst.com',
emailencodingkey='UTF-8', lastname='testL',
languagelocalekey='en_US',
localesidkey='en_US', profileid = p.Id, ContactId = con.Id,
timezonesidkey='America/Los_Angeles',
username='testmailxxx@tst.com');
insert u;
}
List<case>lstcase=new List<case>();
List<RecordType> listRecType = [select Id from RecordType where sObjectType = 'Case' And Name = 'MassBayCC_Ticket'];
System.runAs (u) {
Case cs = new Case(RecordTypeId = listRecType[0].Id,AccountId=acc.Id,ContactId=con.Id);
cs.Spam_criteria__c='Based on Description';
cs.Subject='tesr';
cs.Description='tjkjkjksj kljkjsldk';
cs.SuppliedEmail='shr.jdd@test.com';
cs.Possible_Spam__c=true;
cs.Identified_Keyword__c='s';
lstcase.add(cs);
Case cs1 = new Case(RecordTypeId = listRecType[0].Id,AccountId=acc.Id,ContactId=con.Id);
cs1.Spam_criteria__c='Based on Webmail';
cs1.Subject='tesr';
cs1.Description='tjkjkjksj kljkjsldk';
cs1.SuppliedEmail='shr.jdd@test.com';
cs1.Possible_Spam__c=true;
cs1.Identified_Keyword__c='s';
lstcase.add(cs1);
Case cs2 = new Case(RecordTypeId = listRecType[0].Id,AccountId=acc.Id,ContactId=con.Id);
cs2.Spam_criteria__c='Based on Subject';
cs2.Subject='tesr';
cs2.Description='tjkjkjksj kljkjsldk';
cs2.SuppliedEmail='shr.jdd@test.com';
cs2.Possible_Spam__c=true;
cs2.Identified_Keyword__c='s';
lstcase.add(cs2);
insert lstcase;
}
}
}
please help me i am got 18% code coverage
code coverage not increasing in my apex trigger please help me
my apex code is
trigger autoCreateContactController on Case (before insert) {
for(case cs:Trigger.new)
{
if(lstBasedOnDesc.size()>0)
{
for(String s:lstBasedOnDesc)
{
if((cs.SuppliedEmail).Contains(s))
{
cs.ownerId='00Gd00000027kH7';
}
else {
List<contact> lstcontact= [select id from contact where email=:cs.SuppliedEmail limit 1];
if(lstcontact.size()>0)
{
cs.ContactId=lstcontact.get(0).id;
}
else{
String leftPart = cs.SuppliedEmail.substringBefore('@');
if(leftPart.contains('.')){
String[] leftPartSplitted = leftPart.split('\\.');
//we check if there's one dot in the substring
if(leftPartSplitted.size() == 2 ){
String firstName = leftPartSplitted[0];
String lastName = leftPartSplitted[1];
contact con1 =new contact();
con1.firstname=firstName;
con1.LastName=lastName;
con1.Email=cs.SuppliedEmail;
con1.AccountId='0010W00002MuDcQ';
insert con1;
cs.ContactId=con1.Id;
}
}
else if(leftPart.contains('_')){
String[] leftPartSplitted = leftPart.split('\\_');
if(leftPartSplitted.size()==2)
{
String firstName = leftPartSplitted[0];
String lastName = leftPartSplitted[1];
contact con1 =new contact();
con1.firstname=firstName;
con1.LastName=lastName;
con1.Email=cs.SuppliedEmail;
con1.AccountId='0010W00002MuDcQ';
insert con1;
cs.ContactId=con1.Id;
}
}
else{
String firstName = 'unkown';
String lastName = leftPart;
contact con1 =new contact();
con1.firstname=firstName;
con1.LastName=lastName;
con1.Email=cs.SuppliedEmail;
con1.AccountId='0010W00002MuDcQ';
insert con1;
cs.ContactId=con1.Id;
}}}}}}
and my test class is
@isTest
public class AutoCreateContactControllerTest {
@isTest
public Static void SpamTestmethod()
{ Account acc = new Account(Name='test11');
insert acc;
Contact con = new Contact(AccountId=acc.Id,LastName='test',Email='desd.red@test.tst');
insert con;
Trigger_Control__c tc=new Trigger_Control__c();
tc.Enable_Spam_Controller_Trigger__c=true;
tc.Name='test tc';
insert tc;
User u;
User thisUser = [SELECT Id FROM User WHERE Id = '005d000000187CwAAI'];
System.runAs (thisUser) {
Profile p = [SELECT Id FROM Profile WHERE Name='CH_Tier1-Partner'];
u = new User(alias = 'tstwy', email='testmail@tst.com',
emailencodingkey='UTF-8', lastname='testL',
languagelocalekey='en_US',
localesidkey='en_US', profileid = p.Id, ContactId = con.Id,
timezonesidkey='America/Los_Angeles',
username='testmailxxx@tst.com');
insert u;
}
List<case>lstcase=new List<case>();
List<RecordType> listRecType = [select Id from RecordType where sObjectType = 'Case' And Name = 'MassBayCC_Ticket'];
System.runAs (u) {
Case cs = new Case(RecordTypeId = listRecType[0].Id,AccountId=acc.Id,ContactId=con.Id);
cs.Spam_criteria__c='Based on Description';
cs.Subject='tesr';
cs.Description='tjkjkjksj kljkjsldk';
cs.SuppliedEmail='shr.jdd@test.com';
cs.Possible_Spam__c=true;
cs.Identified_Keyword__c='s';
lstcase.add(cs);
Case cs1 = new Case(RecordTypeId = listRecType[0].Id,AccountId=acc.Id,ContactId=con.Id);
cs1.Spam_criteria__c='Based on Webmail';
cs1.Subject='tesr';
cs1.Description='tjkjkjksj kljkjsldk';
cs1.SuppliedEmail='shr.jdd@test.com';
cs1.Possible_Spam__c=true;
cs1.Identified_Keyword__c='s';
lstcase.add(cs1);
Case cs2 = new Case(RecordTypeId = listRecType[0].Id,AccountId=acc.Id,ContactId=con.Id);
cs2.Spam_criteria__c='Based on Subject';
cs2.Subject='tesr';
cs2.Description='tjkjkjksj kljkjsldk';
cs2.SuppliedEmail='shr.jdd@test.com';
cs2.Possible_Spam__c=true;
cs2.Identified_Keyword__c='s';
lstcase.add(cs2);
insert lstcase;
}
}
}
please help me i am got 18% code coverage
- Sebastian Page
- December 18, 2019
- Like
- 0
Problem in action function with parameters
Hello All,
I am facing issue on action function with parameter. When i calling apex method from javascript then apex method called and create record in salesforce. I want update 3 salesforce fields from javascript variable vlaue value into salesfoce.
My code is here
public class BBH_SurveyCopy {
Public String Survey_comments {get;set;}
public String enteredText1{get;set;}
public String enteredText2{get;set;}
public String enteredText3{get;set;}
Public void createSurvey(){
BBH_Surveys__c bbh=new BBH_Surveys__c();
bbh.Ques1__c=enteredText1;
bbh.Ques2__c=enteredText2;
bbh.Ques3__c=enteredText3;
bbh.Surveys_Name__c='a2yW00000018lN0';
bbh.Survey_Comments__c =Survey_comments;
insert bbh;
}
}
vf page is
<apex:form id="fm" styleClass="Frm-c" >
<apex:pageMessages id="showmsg"></apex:pageMessages>
<apex:inputtextarea styleclass="fgh" value="{!Survey_comments}" cols="80" rows="3" Rendered="{!hidecmtbtn}"/><br/>
<apex:actionFunction name="echo" action="{!createSurvey}">
<apex:param name="firstParam" assignTo="{!enteredText1}" value="" />
<apex:param name="secondParam" assignTo="{!enteredText2}" value=""/>
<apex:param name="thirdParam" assignTo="{!enteredText3}" value="" />
</apex:actionFunction>
<div style="text-align:center; margin-top:40px;">
<apex:commandButton styleClass="asd" value="Update Survey" Rendered="{!modibtn}" onclick="modiresponse(event);" reRender="fm"/>
<apex:commandButton styleClass="asd" onclick="callActionMethod(event);" reRender="showmsg" Rendered="{!hidecmtbtn}" value="Submit Survey"/>
</div>
</apex:form>
function callActionMethod(event)
{
var txtVal1 ='1';
var txtVal2 = '2';
var txtVal3 = '3';
/*Below Method is generated by "apex:actionFunction" which will call Apex Method "echoVal"*/
echo(txtVal1,txtVal2,txtVal3);
}
Please help me on this
I am facing issue on action function with parameter. When i calling apex method from javascript then apex method called and create record in salesforce. I want update 3 salesforce fields from javascript variable vlaue value into salesfoce.
My code is here
public class BBH_SurveyCopy {
Public String Survey_comments {get;set;}
public String enteredText1{get;set;}
public String enteredText2{get;set;}
public String enteredText3{get;set;}
Public void createSurvey(){
BBH_Surveys__c bbh=new BBH_Surveys__c();
bbh.Ques1__c=enteredText1;
bbh.Ques2__c=enteredText2;
bbh.Ques3__c=enteredText3;
bbh.Surveys_Name__c='a2yW00000018lN0';
bbh.Survey_Comments__c =Survey_comments;
insert bbh;
}
}
vf page is
<apex:form id="fm" styleClass="Frm-c" >
<apex:pageMessages id="showmsg"></apex:pageMessages>
<apex:inputtextarea styleclass="fgh" value="{!Survey_comments}" cols="80" rows="3" Rendered="{!hidecmtbtn}"/><br/>
<apex:actionFunction name="echo" action="{!createSurvey}">
<apex:param name="firstParam" assignTo="{!enteredText1}" value="" />
<apex:param name="secondParam" assignTo="{!enteredText2}" value=""/>
<apex:param name="thirdParam" assignTo="{!enteredText3}" value="" />
</apex:actionFunction>
<div style="text-align:center; margin-top:40px;">
<apex:commandButton styleClass="asd" value="Update Survey" Rendered="{!modibtn}" onclick="modiresponse(event);" reRender="fm"/>
<apex:commandButton styleClass="asd" onclick="callActionMethod(event);" reRender="showmsg" Rendered="{!hidecmtbtn}" value="Submit Survey"/>
</div>
</apex:form>
function callActionMethod(event)
{
var txtVal1 ='1';
var txtVal2 = '2';
var txtVal3 = '3';
/*Below Method is generated by "apex:actionFunction" which will call Apex Method "echoVal"*/
echo(txtVal1,txtVal2,txtVal3);
}
Please help me on this
- Sebastian Page
- December 13, 2019
- Like
- 0
Related list quick link component need in lightning community
Hello All,
I have requirment of Related list quick links in lightning community. I am new in lightning admin as well as development so i don't have more knowledge of lightning. Please help me if anyone got solution. I want to same visibility of Related list quick links component in community.
Regards
Sebastian Page
I have requirment of Related list quick links in lightning community. I am new in lightning admin as well as development so i don't have more knowledge of lightning. Please help me if anyone got solution. I want to same visibility of Related list quick links component in community.
Regards
Sebastian Page
- Sebastian Page
- November 18, 2019
- Like
- 0
Some line of apex class is not covered
Hello All
Some line in apex class is not covering please help me.
Some line in apex class is not covering please help me.
public class UpdateAccountManagerEmailAdderss { public Static void updateAccountMgrEmail(List<case> lstcase) { List<String> lstOfDomain=new List<String>(); list <Account> lstAccounts = [Select Id,Account_Manager_Email__c from Account WHERE Old_HD_Provider__c!='ConnectWise' AND Status__c='Live']; Map<String,String>mapAccount=new Map<String,String>(); for(account a:lstAccounts){ mapAccount.put(a.id,a.Account_Manager_Email__c); } Map<string,string> mapDomain=new Map<String,String>(); for(Account ks:[Select id,institutional_EmailDomain__c from Account WHERE Old_HD_Provider__c!='ConnectWise' AND Status__c='Live' and institutional_EmailDomain__c!=null]) { lstOfDomain.add(ks.institutional_EmailDomain__c); mapDomain.put(ks.institutional_EmailDomain__c, ks.id); } for(case cs:lstcase) { if(lstOfDomain.size()>0){ for(String s:lstOfDomain) { if(cs.Description!=null && ( cs.Description).Contains(s)) { cs.AccountId=mapDomain.get(s); cs.Account_Manager_Email__c=mapAccount.get(cs.AccountId); // cs.Identified_Keyword__c=s; } else { if((cs.Description).Contains('Test1ymail')) { cs.Account_Manager_Email__c='Test1ymail'; } if((cs.Description).Contains('Test2ymail')) { cs.Account_Manager_Email__c='Test2ymail'; } if((cs.Description).Contains('Test3ymail')) { cs.Account_Manager_Email__c='Test3ymail'; } } }}}} } test class is @isTest public class UpdateAccountManagerEmailAdderss_Test { @isTest public static void testAcctMgr() { Map<Id,String> mapAccount =new Map<Id,String>(); Map<String,String> mapDomain=new Map<String,String>(); List<string>lstOfDomain=new List<String>(); Account acc =new Account(); acc.name='BlackeBeltHelp Agents'; // acc.Account_Manager_Email__c='test.test@test.com'; acc.Institutional_EmailDomain__c='ben.edu'; insert acc; mapAccount.put(acc.id,acc.Account_Manager_Email__c); mapDomain.put(acc.Institutional_EmailDomain__c,acc.id); lstOfDomain.add(acc.Institutional_EmailDomain__c); Contact con=new Contact(); con.accountId=acc.id; con.firstName='test'; Con.lastName='testcontact'; Con.Email='Shiv@str.tst'; insert con; Trigger_Control__c tc=new Trigger_Control__c(); tc.name='test'; tc.Enable_Update_Account_Mgr_Email_Trigger__c=true; insert tc; List<case>lstcase=new List<case>(); Case cs=new Case(); cs.accountId=acc.id; cs.contactId=con.id; cs.Account_Manager_Email__c=acc.Account_Manager_Email__c; cs.description='kdjksjkfjkjdfsjmk smjkm'; lstcase.add(cs); insert lstcase; UpdateAccountManagerEmailAdderss.updateAccountMgrEmail(lstcase); } }
- Sebastian Page
- July 24, 2019
- Like
- 0
how to use voice to text google library in apex
Hello All,
I need voice to text google liabrary in apex . And How to Import in apex language please help me.
Regards
Sebatian Page
I need voice to text google liabrary in apex . And How to Import in apex language please help me.
Regards
Sebatian Page
- Sebastian Page
- April 22, 2019
- Like
- 0
how to create Email-to-case with attachment
Hello All,
I have created web serivce for Email-to-case and enable "Save Email-to-Case attachments as Salesforce Files" but Ticket not created with attachment .
I have created web serivce for Email-to-case and enable "Save Email-to-Case attachments as Salesforce Files" but Ticket not created with attachment .
- Sebastian Page
- April 22, 2019
- Like
- 0
Governing limit Exception error on my batch class
Hi All ,
i am getting error of governing limit error is " System.LimitException: Too many query rows: 50001"
Batch apex class-
global class SSO_User_count implements database.Batchable<sObject> {
global database.QueryLocator start(database.BatchableContext bc)
{
string query='Select id from account';
return database.getQueryLocator(query);
}
global void execute(database.BatchableContext bc ,List<account> scope)
{
List<Account> updateacc=new List<Account>();
list<account> acclist=[select id,SSO_User_Count__c,ispartner ,iscustomerportal from account where Ispartner=true and IsCustomerPortal=true];
for(Account acc:acclist){
List<user>lstusr=[select id FROM User where isActive=true and User.Profile.UserLicense.Name='Overage High Volume Customer Portal' and accountid=:Acc.id];
// acc.SSO_User_Count__c=lstusr.size();
acc.SSO_User_Count__c=lstusr.size();
scope.add(acc);
}
update scope;
}
global void finish(database.BatchableContext bc)
{
}
}
i am getting error of governing limit error is " System.LimitException: Too many query rows: 50001"
Batch apex class-
global class SSO_User_count implements database.Batchable<sObject> {
global database.QueryLocator start(database.BatchableContext bc)
{
string query='Select id from account';
return database.getQueryLocator(query);
}
global void execute(database.BatchableContext bc ,List<account> scope)
{
List<Account> updateacc=new List<Account>();
list<account> acclist=[select id,SSO_User_Count__c,ispartner ,iscustomerportal from account where Ispartner=true and IsCustomerPortal=true];
for(Account acc:acclist){
List<user>lstusr=[select id FROM User where isActive=true and User.Profile.UserLicense.Name='Overage High Volume Customer Portal' and accountid=:Acc.id];
// acc.SSO_User_Count__c=lstusr.size();
acc.SSO_User_Count__c=lstusr.size();
scope.add(acc);
}
update scope;
}
global void finish(database.BatchableContext bc)
{
}
}
- Sebastian Page
- February 06, 2019
- Like
- 0
I am facing issue to write test class
Hi All,
I am facing issue to write test class for this code please help me i am stuck from one month please help me.
public class CommenttoEmail {
public String Commentbody {get;set;}
public String Set_to{get;set;}
Public String Set_bcc{get;set;}
public String Set_cc{get;set;}
public List<String> SetTo {get;set;}
public List<String> SetCC {get;set;}
public List<String> SetBCC{get;set;}
Public String CaseId {get;set;}
public String Selec {get;set;}
public List<String> liststatus {get;set;}
public boolean flag {set;get;}
public string Str2;
public String test;
Public List<string> listall {get;set;}
public Attachment attachment {
get {
if (attachment == null)
attachment = new Attachment();
return attachment;
}
set;
}
public CommenttoEmail(apexpages.StandardController std)
{
liststatus=new List<string>{'New','Escalated','On Hold','Action-Automated Escalation','Agent Research','Scheduled','Awaiting Customer Reply',
'Awaiting External Response','Awaiting Part','Re-Opened','Closed Successful','Closed Unsuccessful'};
flag=false;
CaseId=ApexPages.CurrentPage().getParameters().get('Id');
listall=new List<String>();
SetTo=new List<String>{};
SetCC=new List<String>{};
SetBCC=new List<String>{};
}
public void senttoEmail()
{
Case cse = [select id ,CaseNumber ,Status,ContactEmail,subject from case where id=:caseId];
SetTo=Set_To.split(',');
}
public void bccEmail()
{
SetBCC=Set_bcc.split(',');
}
public void ccEmail()
{
SetCC=Set_cc.split(',');
}
public void ss()
{
senttoEmail();
bccEmail();
ccEmail();
}
public void attachemail()
{
listall.addAll(SetTo);
listall.addAll(SetBCC);
listall.addAll(SetCC);
}
// this method used for creating case comment
public pagereference createCaseComment(){
ss();
upload();
attachemail();
sendingEmail();
ChangeStatus();
Case cse = [select id ,CaseNumber ,Status, Contact.name,Account.name,subject from case where id=:caseId];
String ss=string.join(listall, ',');
String Str1='\n\n';
String Str0='[Recipients:' +ss+']';
String Str3=cse.Contact.name+',\n\n';
String Reg='\n\n\n Sincerely,\n'+cse.Contact.name+'\n'+cse.Account.name;
Str2=Str0+Str1+Str3+Commentbody+Reg;
CaseComment cc = new CaseComment(ParentId = cse.Id,CommentBody = str2 , IsPublished=true);
insert cc;
pagereference pg =new pagereference('/'+CaseId);
return pg;
}
// this method used for sending email
public PageReference sendingEmail()
{
upload();
Case[] cse = [select id ,CaseNumber ,Status, Contact.name,Account.name,subject from case where id=:caseId limit 1];
String ss=string.join(listall, ',');
String Str3=cse[0].Contact.name+',\n\n';
String Reg='\n\n\n Sincerely,\n'+cse[0].Contact.name+'\n'+cse[0].Account.name;
Str2=Str3+Commentbody+Reg;
List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
List<Attachment> Attlist=[select Name, Body, BodyLength from Attachment where ParentId = :caseId];
for (Attachment a :Attlist ){
Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
efa.setFileName(a.Name);
efa.setBody(a.Body);
fileAttachments.add(efa);
}
try{
Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
semail.setToAddresses(SetTo);
semail.setBccAddresses(SetBCC);
semail.setCcAddresses(SetCC);
semail.setSubject(cse[0].Subject);
semail.setPlainTextBody(Str2);
semail.setFileAttachments(fileAttachments);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {semail});
}catch(exception e)
{}
return null;
}
//This method use for redirect to current ticket.
public pagereference redirectCasePage()
{
CaseId=ApexPages.CurrentPage().getParameters().get('Id');
pagereference pg =new pagereference('/'+CaseId);
return pg;
}
//This Method used for change status
public void ChangeStatus()
{
List<Case> cse = [select id ,CaseNumber ,Status,subject from case where id=:caseId];
for(Case c:cse){
if(selec=='New')
{
c.Status='New';
}
if(selec=='Escalated')
{
c.Status='Escalated';
}
if(selec=='On Hold')
{
c.Status='On Hold';
}
if(selec=='Action-Automated Escalation')
{
c.Status='Action-Automated Escalation';
}
if(selec=='Agent Research')
{
c.Status='Agent Research';
}
if(selec=='Scheduled')
{
c.Status='Scheduled';
}
if(selec=='Action-Automated Escalation')
{
c.Status='Action-Automated Escalation';
}
if(selec=='Awaiting Customer Reply')
{
c.Status='Awaiting Customer Reply';
}
if(selec=='Awaiting External Response')
{
c.Status='Awaiting External Response';
}
if(selec=='Awaiting Part')
{
c.Status='Awaiting Part';
}if(selec=='Re-Opened')
{
c.Status='Re-Opened';
}if(selec=='Closed Successful')
{
c.Status='Closed Successful';
}if(selec=='Closed Unsuccessful')
{
c.Status='Closed Unsuccessful';
}
update c;
}
}
// This Method create for status display in custom picklist
public List<SelectOption> getCaseStatus()
{
List<SelectOption> optlist=new List<SelectOption>();
Case[] cse = [select id ,CaseNumber ,Status,subject from case where id=:caseId limit 1];
optlist.add(new SelectOption(cse[0].Status,cse[0].Status));
for(String s:liststatus)
{
optlist.add(new SelectOption(s,s));
}
return optlist;
}
//This Method Created for uploading file
public PageReference upload() {
attachment.OwnerId = UserInfo.getUserId();
attachment.ParentId = CaseId;
attachment.IsPrivate = true;
attachment.ContentType = 'image/jpeg';
try {
insert attachment;
} catch (DMLException e) {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
return null;
} finally {
attachment = new Attachment();
}
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Attachment uploaded successfully'));
return null;
}
}
I am facing issue to write test class for this code please help me i am stuck from one month please help me.
public class CommenttoEmail {
public String Commentbody {get;set;}
public String Set_to{get;set;}
Public String Set_bcc{get;set;}
public String Set_cc{get;set;}
public List<String> SetTo {get;set;}
public List<String> SetCC {get;set;}
public List<String> SetBCC{get;set;}
Public String CaseId {get;set;}
public String Selec {get;set;}
public List<String> liststatus {get;set;}
public boolean flag {set;get;}
public string Str2;
public String test;
Public List<string> listall {get;set;}
public Attachment attachment {
get {
if (attachment == null)
attachment = new Attachment();
return attachment;
}
set;
}
public CommenttoEmail(apexpages.StandardController std)
{
liststatus=new List<string>{'New','Escalated','On Hold','Action-Automated Escalation','Agent Research','Scheduled','Awaiting Customer Reply',
'Awaiting External Response','Awaiting Part','Re-Opened','Closed Successful','Closed Unsuccessful'};
flag=false;
CaseId=ApexPages.CurrentPage().getParameters().get('Id');
listall=new List<String>();
SetTo=new List<String>{};
SetCC=new List<String>{};
SetBCC=new List<String>{};
}
public void senttoEmail()
{
Case cse = [select id ,CaseNumber ,Status,ContactEmail,subject from case where id=:caseId];
SetTo=Set_To.split(',');
}
public void bccEmail()
{
SetBCC=Set_bcc.split(',');
}
public void ccEmail()
{
SetCC=Set_cc.split(',');
}
public void ss()
{
senttoEmail();
bccEmail();
ccEmail();
}
public void attachemail()
{
listall.addAll(SetTo);
listall.addAll(SetBCC);
listall.addAll(SetCC);
}
// this method used for creating case comment
public pagereference createCaseComment(){
ss();
upload();
attachemail();
sendingEmail();
ChangeStatus();
Case cse = [select id ,CaseNumber ,Status, Contact.name,Account.name,subject from case where id=:caseId];
String ss=string.join(listall, ',');
String Str1='\n\n';
String Str0='[Recipients:' +ss+']';
String Str3=cse.Contact.name+',\n\n';
String Reg='\n\n\n Sincerely,\n'+cse.Contact.name+'\n'+cse.Account.name;
Str2=Str0+Str1+Str3+Commentbody+Reg;
CaseComment cc = new CaseComment(ParentId = cse.Id,CommentBody = str2 , IsPublished=true);
insert cc;
pagereference pg =new pagereference('/'+CaseId);
return pg;
}
// this method used for sending email
public PageReference sendingEmail()
{
upload();
Case[] cse = [select id ,CaseNumber ,Status, Contact.name,Account.name,subject from case where id=:caseId limit 1];
String ss=string.join(listall, ',');
String Str3=cse[0].Contact.name+',\n\n';
String Reg='\n\n\n Sincerely,\n'+cse[0].Contact.name+'\n'+cse[0].Account.name;
Str2=Str3+Commentbody+Reg;
List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
List<Attachment> Attlist=[select Name, Body, BodyLength from Attachment where ParentId = :caseId];
for (Attachment a :Attlist ){
Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
efa.setFileName(a.Name);
efa.setBody(a.Body);
fileAttachments.add(efa);
}
try{
Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
semail.setToAddresses(SetTo);
semail.setBccAddresses(SetBCC);
semail.setCcAddresses(SetCC);
semail.setSubject(cse[0].Subject);
semail.setPlainTextBody(Str2);
semail.setFileAttachments(fileAttachments);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {semail});
}catch(exception e)
{}
return null;
}
//This method use for redirect to current ticket.
public pagereference redirectCasePage()
{
CaseId=ApexPages.CurrentPage().getParameters().get('Id');
pagereference pg =new pagereference('/'+CaseId);
return pg;
}
//This Method used for change status
public void ChangeStatus()
{
List<Case> cse = [select id ,CaseNumber ,Status,subject from case where id=:caseId];
for(Case c:cse){
if(selec=='New')
{
c.Status='New';
}
if(selec=='Escalated')
{
c.Status='Escalated';
}
if(selec=='On Hold')
{
c.Status='On Hold';
}
if(selec=='Action-Automated Escalation')
{
c.Status='Action-Automated Escalation';
}
if(selec=='Agent Research')
{
c.Status='Agent Research';
}
if(selec=='Scheduled')
{
c.Status='Scheduled';
}
if(selec=='Action-Automated Escalation')
{
c.Status='Action-Automated Escalation';
}
if(selec=='Awaiting Customer Reply')
{
c.Status='Awaiting Customer Reply';
}
if(selec=='Awaiting External Response')
{
c.Status='Awaiting External Response';
}
if(selec=='Awaiting Part')
{
c.Status='Awaiting Part';
}if(selec=='Re-Opened')
{
c.Status='Re-Opened';
}if(selec=='Closed Successful')
{
c.Status='Closed Successful';
}if(selec=='Closed Unsuccessful')
{
c.Status='Closed Unsuccessful';
}
update c;
}
}
// This Method create for status display in custom picklist
public List<SelectOption> getCaseStatus()
{
List<SelectOption> optlist=new List<SelectOption>();
Case[] cse = [select id ,CaseNumber ,Status,subject from case where id=:caseId limit 1];
optlist.add(new SelectOption(cse[0].Status,cse[0].Status));
for(String s:liststatus)
{
optlist.add(new SelectOption(s,s));
}
return optlist;
}
//This Method Created for uploading file
public PageReference upload() {
attachment.OwnerId = UserInfo.getUserId();
attachment.ParentId = CaseId;
attachment.IsPrivate = true;
attachment.ContentType = 'image/jpeg';
try {
insert attachment;
} catch (DMLException e) {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
return null;
} finally {
attachment = new Attachment();
}
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Attachment uploaded successfully'));
return null;
}
}
- Sebastian Page
- November 29, 2018
- Like
- 0
Need help on Test class and code coverage
Hello All, I am facing issue on test class. My test class execute successfully but code coverage is None please Help.
My apex class here
@istest
public class CommenttoEmailTest {
static testMethod void testMatching(){
// Id rtId = [select Id, name from RecordType where name = 'Massbay_Ticket' and SObjectType = 'Case' limit 1].Id;
//create account
Account acc = new Account();
//enter details
acc.Name = 'Test Account';
//Add other fields
insert acc;
// create test contact
Contact con = TestUtilityController.getContact('Test Last Name','testing@testing.com',acc.Id);
insert con;
// Create test cases
List<Case> listCase = new List<Case>();
if(UtilityController.caseRecordType.containsKey('Massbay_Ticket')){
String recordTypeId = UtilityController.caseRecordType.get('Massbay_Ticket').Id;
Case csa = TestUtilityController.getCase(recordTypeId,con.Id,acc.Id);
//enter details
//Add other fields
csa.Ticket_Category__c='Blackboard learn';
csa.Status = 'Action-Automated Escalation';
insert csa;
PageReference pageRef = Page.MyNew_commentvf;
pageRef.getParameters().put(recordTypeId, String.valueOf(csa.Id));
Test.setCurrentPage(pageRef);
CaseComment tComment = new CaseComment();
tComment.ParentId = Csa.Id;
tComment.CommentBody = 'Some Comment';
tComment.IsPublished = TRUE;
insert tComment;
tComment.CommentBody = 'Inporgreess Comment';
update tComment ;
ApexPages.StandardController sc = new ApexPages.StandardController(csa);
CommenttoEmail testCmEmail = new CommenttoEmail (sc);
testCmEmail.senttoEmail();
testCmEmail.bccEmail();
testCmEmail.ccEmail();
testCmEmail.attachemail();
testCmEmail.createCaseComment();
testCmEmail.sendingEmail();
testCmEmail.ss();
testCmEmail.ChangeStatus();
testCmEmail.getCaseStatus();
testCmEmail.upload();
}
}// end of test method
}// end of Class
and my test class is
@istest
public class CommenttoEmailTest {
static testMethod void testMatching(){
// Id rtId = [select Id, name from RecordType where name = 'Massbay_Ticket' and SObjectType = 'Case' limit 1].Id;
//create account
Account acc = new Account();
//enter details
acc.Name = 'Test Account';
//Add other fields
insert acc;
// create test contact
Contact con = TestUtilityController.getContact('Test Last Name','testing@testing.com',acc.Id);
insert con;
// Create test cases
List<Case> listCase = new List<Case>();
if(UtilityController.caseRecordType.containsKey('Massbay_Ticket')){
String recordTypeId = UtilityController.caseRecordType.get('Massbay_Ticket').Id;
Case csa = TestUtilityController.getCase(recordTypeId,con.Id,acc.Id);
//enter details
//Add other fields
csa.Ticket_Category__c='Blackboard learn';
csa.Status = 'Action-Automated Escalation';
insert csa;
PageReference pageRef = Page.MyNew_commentvf;
pageRef.getParameters().put(recordTypeId, String.valueOf(csa.Id));
Test.setCurrentPage(pageRef);
CaseComment tComment = new CaseComment();
tComment.ParentId = Csa.Id;
tComment.CommentBody = 'Some Comment';
tComment.IsPublished = TRUE;
insert tComment;
tComment.CommentBody = 'Inporgreess Comment';
update tComment ;
ApexPages.StandardController sc = new ApexPages.StandardController(csa);
CommenttoEmail testCmEmail = new CommenttoEmail (sc);
testCmEmail.senttoEmail();
testCmEmail.bccEmail();
testCmEmail.ccEmail();
testCmEmail.attachemail();
testCmEmail.createCaseComment();
testCmEmail.sendingEmail();
testCmEmail.ss();
testCmEmail.ChangeStatus();
testCmEmail.getCaseStatus();
testCmEmail.upload();
}
}// end of test method
}// end of Class
My apex class here
@istest
public class CommenttoEmailTest {
static testMethod void testMatching(){
// Id rtId = [select Id, name from RecordType where name = 'Massbay_Ticket' and SObjectType = 'Case' limit 1].Id;
//create account
Account acc = new Account();
//enter details
acc.Name = 'Test Account';
//Add other fields
insert acc;
// create test contact
Contact con = TestUtilityController.getContact('Test Last Name','testing@testing.com',acc.Id);
insert con;
// Create test cases
List<Case> listCase = new List<Case>();
if(UtilityController.caseRecordType.containsKey('Massbay_Ticket')){
String recordTypeId = UtilityController.caseRecordType.get('Massbay_Ticket').Id;
Case csa = TestUtilityController.getCase(recordTypeId,con.Id,acc.Id);
//enter details
//Add other fields
csa.Ticket_Category__c='Blackboard learn';
csa.Status = 'Action-Automated Escalation';
insert csa;
PageReference pageRef = Page.MyNew_commentvf;
pageRef.getParameters().put(recordTypeId, String.valueOf(csa.Id));
Test.setCurrentPage(pageRef);
CaseComment tComment = new CaseComment();
tComment.ParentId = Csa.Id;
tComment.CommentBody = 'Some Comment';
tComment.IsPublished = TRUE;
insert tComment;
tComment.CommentBody = 'Inporgreess Comment';
update tComment ;
ApexPages.StandardController sc = new ApexPages.StandardController(csa);
CommenttoEmail testCmEmail = new CommenttoEmail (sc);
testCmEmail.senttoEmail();
testCmEmail.bccEmail();
testCmEmail.ccEmail();
testCmEmail.attachemail();
testCmEmail.createCaseComment();
testCmEmail.sendingEmail();
testCmEmail.ss();
testCmEmail.ChangeStatus();
testCmEmail.getCaseStatus();
testCmEmail.upload();
}
}// end of test method
}// end of Class
and my test class is
@istest
public class CommenttoEmailTest {
static testMethod void testMatching(){
// Id rtId = [select Id, name from RecordType where name = 'Massbay_Ticket' and SObjectType = 'Case' limit 1].Id;
//create account
Account acc = new Account();
//enter details
acc.Name = 'Test Account';
//Add other fields
insert acc;
// create test contact
Contact con = TestUtilityController.getContact('Test Last Name','testing@testing.com',acc.Id);
insert con;
// Create test cases
List<Case> listCase = new List<Case>();
if(UtilityController.caseRecordType.containsKey('Massbay_Ticket')){
String recordTypeId = UtilityController.caseRecordType.get('Massbay_Ticket').Id;
Case csa = TestUtilityController.getCase(recordTypeId,con.Id,acc.Id);
//enter details
//Add other fields
csa.Ticket_Category__c='Blackboard learn';
csa.Status = 'Action-Automated Escalation';
insert csa;
PageReference pageRef = Page.MyNew_commentvf;
pageRef.getParameters().put(recordTypeId, String.valueOf(csa.Id));
Test.setCurrentPage(pageRef);
CaseComment tComment = new CaseComment();
tComment.ParentId = Csa.Id;
tComment.CommentBody = 'Some Comment';
tComment.IsPublished = TRUE;
insert tComment;
tComment.CommentBody = 'Inporgreess Comment';
update tComment ;
ApexPages.StandardController sc = new ApexPages.StandardController(csa);
CommenttoEmail testCmEmail = new CommenttoEmail (sc);
testCmEmail.senttoEmail();
testCmEmail.bccEmail();
testCmEmail.ccEmail();
testCmEmail.attachemail();
testCmEmail.createCaseComment();
testCmEmail.sendingEmail();
testCmEmail.ss();
testCmEmail.ChangeStatus();
testCmEmail.getCaseStatus();
testCmEmail.upload();
}
}// end of test method
}// end of Class
- Sebastian Page
- November 20, 2018
- Like
- 0
How can be extract all picklist values Using apex
I have a requirment to fetch the details of a record type (case Object) and present in JSON.
Among other fields on the Record type, there are few dependent Picklist fields :
Ticket Category (Controlling Ticket Type)
Ticket Type (controlling Ticket Item)
Ticket Item
I am suppose to extract all the mappings of the picklists and fields on the record type page layout.
If some one have worked on a similar requirement, please suggest how this can be achieved.
Thanks and Regards
Sebastian Page
Among other fields on the Record type, there are few dependent Picklist fields :
Ticket Category (Controlling Ticket Type)
Ticket Type (controlling Ticket Item)
Ticket Item
I am suppose to extract all the mappings of the picklists and fields on the record type page layout.
If some one have worked on a similar requirement, please suggest how this can be achieved.
Thanks and Regards
Sebastian Page
- Sebastian Page
- March 18, 2021
- Like
- 0
Why Some line of the code is not covering
Hi All
Why Some line is not covering code coverage .
I am using test class here
@isTest
public class CaseMergeHandlerTest {
static testMethod void testMerge(){
List<String>DupCase =new List<string>();
Account testAccount = new Account(Name='Test Company Name123');
insert testAccount;
Contact con = new Contact(LastName='Testcont' ,Email='sss@test.com', AccountId=testAccount.id);
insert con;
list<case>lstcase =new LIst<case>();
Case caseObj1 = new Case();
caseObj1.AccountId = testAccount.Id;
caseObj1.contactId=con.id;
caseObj1.Status = 'Action-Automated Escalation';
caseObj1.Origin ='Email';
lstcase.add(caseObj1);
DupCase.add(caseObj1.id);
Case caseObj2 = new Case();
caseObj2.AccountId = testAccount.Id;
caseObj2.contactId=con.id;
caseObj2.Status = 'Closed Duplicate';
caseObj2.Origin ='Email';
lstcase.add(caseObj2);
DupCase.add(caseObj2.id);
test.startTest();
insert lstcase;
attachment attach=new attachment();
attach.name='test.html';
Blob bodyBlob=Blob.valueOf('Unit Test Attachment Body');
attach.body=bodyBlob;
attach.parentId=lstcase[0].id;
insert attach;
List<Attachment> attachments=[select id, name from Attachment where parent.id=:lstcase[0].id];
System.assertEquals(1, attachments.size());
CaseMergeEmail.casAttachment(DupCase, caseObj1.id);
CaseMergeEmail.CasCommnet(DupCase, caseObj1.id);
test.stopTest();
}
}
Please help on this issue.
- Sebastian Page
- September 17, 2020
- Like
- 0
Problem in test class i am getting only 36% code coverage
Hi Salesforce Expert,
We are getting only 36% code coverage in our apex class. my Apex trigger please help me apex code is here-
And test class is
code which is not covering is below here--
We are getting only 36% code coverage in our apex class. my Apex trigger please help me apex code is here-
trigger EmailSendToOwnerUpdate on Case (before update) { // this is a list for storing email for settoAddress List<String>toAddress =new List<String>(); // this is a list for storing email for setccAddress List<String>CCAddress =new List<String>(); List<contact> lstcont=[select id ,Email,name,phone from contact]; Map<String,String> mapContact=new Map<String,String>(); list<String> ccAddresslst=new List<String>(); map<string,String> mapuser=new map<string,string>(); String ownerName=''; String baseUrl = URL.getSalesforceBaseUrl().toExternalForm(); //for getting user email and store in map where user id is key and email is value for(User u:[select id, name, Email from user]) { mapuser.put(u.id,u.email); } //for getting Contact name and store in map where id is key and name is value for(contact con:lstcont) { mapContact.put(con.id,con.name); } for(case cs:trigger.new) { if(cs.total_attachments__c>=1) { case oldcase=Trigger.oldMap.get(cs.id); if(oldcase.OwnerId!=cs.OwnerId) { if(string.valueOf(cs.OwnerId).startsWith('005')) { toAddress.add(mapuser.get(cs.OwnerId)); ownerName=Getqueuemember.getOwnername(cs.OwnerId); } else{ CCAddress=Getqueuemember.getEmailfromuser(cs.OwnerId); ownerName=Getqueuemember.getqueueOwnername(cs.OwnerId); } List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>(); List<Attachment> attlist=[select Name, Body, BodyLength from Attachment where ParentId = :cs.id ]; for (Attachment a :attlist){ Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment(); efa.setFileName(a.Name); efa.setBody(a.Body); fileAttachments.add(efa); } String Subject='Apex template Ticket #'+cs.CaseNumber+' has been assigned to '+' '+ownerName; try{ EmailTemplate et = [SELECT Id,Subject, Body FROM EmailTemplate WHERE DeveloperName ='Sebastian_page']; Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage(); semail.setSubject(Subject); semail.setSenderDisplayName('Salesforce Support'); semail.setTargetObjectId(cs.ContactId); //semail.setTemplateId(et.id); semail.setCcAddresses(CCAddress); semail.setToAddresses(toAddress); semail.setHtmlBody('***THIS IS A SYSTEM GENERATED MESSAGE! DO NOT REPLY!***<br/><br/>Please be advised that the following SalesForce ticket has been assigned to '+ownerName+'<br/><br/> Ticket #:'+cs.CaseNumber+ '<br/>Subject:'+cs.subject+'<br/><br/>Contact Name: '+mapContact.get(cs.Contactid)+'<br/>Contact Phone (primary): '+Getqueuemember.r(cs.ContactPhone)+'<br/>Contact Mobile (primary): '+Getqueuemember.r(cs.ContactMobile)+ '<br/> Contact Email:'+Getqueuemember.r(cs.ContactEmail)+'<br/><br/>Category: '+Getqueuemember.r(cs.Ticket_Category__c)+Getqueuemember.r(cs.Service_Category__c)+Getqueuemember.r(cs.Ticket_Category2__c)+ '<br/>Type: '+Getqueuemember.r(cs.Ticket_Type__c)+Getqueuemember.r(cs.Service_Type__c)+Getqueuemember.r(cs.Ticket_Type2__c)+ '<br/>Item: '+Getqueuemember.r(cs.Ticket_Item__c)+Getqueuemember.r(cs.Service_Item__c)+Getqueuemember.r(cs.Ticket_Item2__c)+ '<br/>Ticket Source: '+Getqueuemember.r(cs.Case_Source__c)+'<br/><br/><br/>Building: '+Getqueuemember.r(cs.building__c)+'<br/>Room: '+Getqueuemember.r(cs.Room_Number__c)+'<br/>Area Description: '+Getqueuemember.r(cs.Area_description__c)+ '<br/><br/><br/>Click the appropriate link below to view the ticket directly:<br/><br/>Partner Portal Users: <a href='+baseUrl+'/'+cs.id+'>'+baseUrl+'/'+cs.id+'</a><br/>BlackbeltHelp (Community Users): <a href='+Getqueuemember.getcommunityurl(cs.AccountId)+cs.id+ '>'+Getqueuemember.getcommunityurl(cs.AccountId)+cs.id+'</a><br/><br/>Description:'+cs.Description+'<br/><br/>Internal Notes: '+Getqueuemember.r(cs.Internal_Notes__c)); semail.setFileAttachments(fileAttachments); semail.setWhatId(cs.id); Messaging.sendEmail(new Messaging.SingleEmailMessage[] {semail}); } catch(exception e) {} } } } }
And test class is
@isTest public class TestEmailSendToOwner { @isTest public Static void emailTest() { // create test account Account acc = TestUtilityController.getAccount('MassBay'); insert acc; // create test contact Contact con = TestUtilityController.getContact('Test Last Name','testing@testing.com',acc.Id); insert con; // fill utility UtilityController.fillUtilities(); UtilityController.isUtility = false; // Create test cases List<Case> listCase = new List<Case>(); if(UtilityController.caseRecordType.containsKey('MassBayCC_Ticket')){ String recordTypeId = UtilityController.caseRecordType.get('MassBayCC_Ticket').Id; Case csanew = TestUtilityController.getCase(recordTypeId,con.Id,acc.Id); csanew.status = 'Action - Automated Escalation'; csanew.total_attachments__c=2; csanew.Ticket_Category2__c = 'Blackboard Learn - LMS'; csanew.Ticket_Type2__c = 'Faculty/Staff'; csanew.Ticket_Item2__c='Tutorial'; listCase.add(csanew); insert listCase; Getqueuemember.getcommunityurl(acc.id); Getqueuemember.getEmailfromuser(listCase[0].ownerId); Getqueuemember.getOwnername(listCase[0].ownerId); Getqueuemember.r(csanew.Ticket_Category2__c); } } }
code which is not covering is below here--
if(string.valueOf(cs.OwnerId).startsWith('005')) { toAddress.add(mapuser.get(cs.OwnerId)); ownerName=Getqueuemember.getOwnername(cs.OwnerId); } else{ CCAddress=Getqueuemember.getEmailfromuser(cs.OwnerId); ownerName=Getqueuemember.getqueueOwnername(cs.OwnerId); } List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>(); List<Attachment> attlist=[select Name, Body, BodyLength from Attachment where ParentId = :cs.id ]; for (Attachment a :attlist){ Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment(); efa.setFileName(a.Name); efa.setBody(a.Body); fileAttachments.add(efa); } String Subject='Apex template Ticket #'+cs.CaseNumber+' has been assigned to '+' '+ownerName; try{ EmailTemplate et = [SELECT Id,Subject, Body FROM EmailTemplate WHERE DeveloperName ='Sebastian_page']; Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage(); semail.setSubject(Subject); semail.setSenderDisplayName('Salesforce Support'); semail.setTargetObjectId(cs.ContactId); //semail.setTemplateId(et.id); semail.setCcAddresses(CCAddress); semail.setToAddresses(toAddress); semail.setHtmlBody('***THIS IS A SYSTEM GENERATED MESSAGE! DO NOT REPLY!***<br/><br/>Please be advised that the following SalesForce ticket has been assigned to '+ownerName+'<br/><br/> Ticket #:'+cs.CaseNumber+ '<br/>Subject:'+cs.subject+'<br/><br/>Contact Name: '+mapContact.get(cs.Contactid)+'<br/>Contact Phone (primary): '+Getqueuemember.r(cs.ContactPhone)+'<br/>Contact Mobile (primary): '+Getqueuemember.r(cs.ContactMobile)+ '<br/> Contact Email:'+Getqueuemember.r(cs.ContactEmail)+'<br/><br/>Category: '+Getqueuemember.r(cs.Ticket_Category__c)+Getqueuemember.r(cs.Service_Category__c)+Getqueuemember.r(cs.Ticket_Category2__c)+ '<br/>Type: '+Getqueuemember.r(cs.Ticket_Type__c)+Getqueuemember.r(cs.Service_Type__c)+Getqueuemember.r(cs.Ticket_Type2__c)+ '<br/>Item: '+Getqueuemember.r(cs.Ticket_Item__c)+Getqueuemember.r(cs.Service_Item__c)+Getqueuemember.r(cs.Ticket_Item2__c)+ '<br/>Ticket Source: '+Getqueuemember.r(cs.Case_Source__c)+'<br/><br/><br/>Building: '+Getqueuemember.r(cs.building__c)+'<br/>Room: '+Getqueuemember.r(cs.Room_Number__c)+'<br/>Area Description: '+Getqueuemember.r(cs.Area_description__c)+ '<br/><br/><br/>Click the appropriate link below to view the ticket directly:<br/><br/>Partner Portal Users: <a href='+baseUrl+'/'+cs.id+'>'+baseUrl+'/'+cs.id+'</a><br/>BlackbeltHelp (Community Users): <a href='+Getqueuemember.getcommunityurl(cs.AccountId)+cs.id+ '>'+Getqueuemember.getcommunityurl(cs.AccountId)+cs.id+'</a><br/><br/>Description:'+cs.Description+'<br/><br/>Internal Notes: '+Getqueuemember.r(cs.Internal_Notes__c)); semail.setFileAttachments(fileAttachments); semail.setWhatId(cs.id); Messaging.sendEmail(new Messaging.SingleEmailMessage[] {semail}); } catch(exception e) {} } } } }
- devloper sfdc
- February 05, 2020
- Like
- 0
problem in test class i can't understand why is happening we got only 33 % code coverage
trigger SpamControllerTrigger on Case (before insert) { /*===================================================hhjjf====================================*/ List<String> lstBasedOnDesc=new List<String>(); for(Keywords__c ks:[Select name from Keywords__c]) { lstBasedOnDesc.add(ks.name); } List<String>LstSpamkeyword=new List<String>(); /*===================================================hhjjf====================================*/ for(Trigger_Control__c tc:Trigger_Control__c.getAll().values()) { if( tc.Enable_Spam_Controller_Trigger__c==true) { for(case cs:Trigger.new) { if(userinfo.getName()=='Automated Workflow') { if(lstBasedOnDesc.size()>0) { for(String s:lstBasedOnDesc) { if(cs.Description!=null && ( cs.Description).Contains(s)) { cs.ownerId='00Gd00000027kH7'; cs.Spam_criteria__c='Based on Description'; cs.Possible_Spam__c=true; cs.Identified_Keyword__c=s; } else if(cs.Subject!=null && (cs.Subject).Contains(s)) { cs.ownerId='00Gd00000027kH7';cs.Spam_criteria__c='Based on Subject'; cs.Possible_Spam__c=true;cs.Identified_Keyword__c=s; } else if((cs.SuppliedEmail).Contains(s)) { cs.ownerId='00Gd00000027kH7'; cs.Spam_criteria__c='Based on Webmail'; cs.Possible_Spam__c=true; cs.Identified_Keyword__c=s; } if(cs.Subject==null || cs.Description==null) { cs.ownerId='00Gd00000027kH7'; cs.Spam_criteria__c='Blank Description / Subject'; cs.Possible_Spam__c=true; cs.Identified_Keyword__c='Blank Subject or Description'; } } } } } } } }Hi All,
We are getting only 33% code coverage . And rest of lines is showing in red color that not cover.
my test class is here-
@isTest public class SpamControllerTriggerTest { @isTest public Static void SpamTestmethod() { Profile pf = [SELECT Id FROM Profile WHERE Name = 'System Administrator']; User tuser = new User(lastName = 'Automated Workflow', email = 'AutomatedWorkflow@test.org', Username = 'AutomatedWorkflow@test123.org', EmailEncodingKey = 'ISO-8859-1', Alias = 'AW', TimeZoneSidKey = 'America/Los_Angeles', LocaleSidKey = 'en_US', LanguageLocaleKey = 'en_US', ProfileId = pf.Id); insert tuser; system.runAs(tuser){ Account acc = new Account(Name='MassBay'); insert acc; Contact con = new Contact(AccountId=acc.Id,LastName='test',Email='desd.red@test.tst'); insert con; Trigger_Control__c tc=new Trigger_Control__c(); tc.Enable_Spam_Controller_Trigger__c=true; tc.Name='test tc'; insert tc; List<case>lstcase=new List<case>(); List<RecordType> listRecType = [select Id from RecordType where sObjectType = 'Case' And Name = 'MassBayCC_Ticket']; Case cs = new Case(RecordTypeId = listRecType[0].Id,AccountId=acc.Id,ContactId=con.Id); cs.Spam_criteria__c='Based on Description'; cs.Subject='tesr'; cs.Description='Test Description1'; cs.SuppliedEmail='shr.jdd@test.com'; cs.Possible_Spam__c=true; cs.Identified_Keyword__c='s'; lstcase.add(cs); Case cs1 = new Case(RecordTypeId = listRecType[0].Id,AccountId=acc.Id,ContactId=con.Id); cs1.Spam_criteria__c='Based on Webmail'; cs1.Subject='tesr'; cs1.Description='Test Description 2'; cs1.SuppliedEmail='shr.jdd@test.com'; cs1.Possible_Spam__c=true; cs1.Identified_Keyword__c='s'; lstcase.add(cs1); Case cs2 = new Case(RecordTypeId = listRecType[0].Id,AccountId=acc.Id,ContactId=con.Id); cs2.Spam_criteria__c='Based on Subject'; cs2.Subject='tesr'; cs2.Description='Test Description 3'; cs2.SuppliedEmail='shr.jdd@test.com'; cs2.Possible_Spam__c=true; cs2.Identified_Keyword__c='s'; lstcase.add(cs2); insert lstcase; } } }
- Sebastian Page
- January 08, 2020
- Like
- 0
problem in test code i have got 13 percent code coverage
Hi All,
I am facing issue of our test class we only got 13 perent code coverage please help
me
trigger autoCreateContactController on Case (before insert) {
for(Trigger_Control__c tc:Trigger_Control__c.getAll().values())
{
if( tc.Enable_Auto_Create_contact_Trigger__c==true)
{
for(case cs:trigger.new)
{
if(userinfo.getName()=='Automated Workflow'){
contact[] lstcontact= [select id from contact where email=:cs.SuppliedEmail limit 1];
if(!lstcontact.isEmpty())
{
String contId=lstcontact[0].id;
if(contId!=null)
{
cs.ContactId=contId;
}
}
else {
String leftPart = cs.Suppliedname;
String[] leftPartSplitted = leftPart.split('\\s+');
if(leftPart!=null || leftPart!='')
{
if(leftPartSplitted.size() == 3)
{
String firstName = leftPartSplitted[0];
String lastName = leftPartSplitted[1];
String middlename=leftPartSplitted[2];
contact con1 =new contact();
con1.firstname=firstName;
con1.LastName=lastName+middlename;
con1.Email=cs.SuppliedEmail;
con1.AccountId='0010W00002MuDcQQAV';
insert con1;
cs.ContactId=con1.Id;
}
else if(leftPartSplitted.size() == 2)
{
String firstName = leftPartSplitted[0];
String lastName = leftPartSplitted[1];
contact con1 =new contact();
con1.firstname=firstName;
con1.LastName=lastName;
con1.Email=cs.SuppliedEmail;
con1.AccountId='0010W00002MuDcQQAV';
insert con1;
cs.ContactId=con1.Id;
}
else if(leftPartSplitted.size() == 1)
{
String lastName = leftPartSplitted[0];
contact con1 =new contact();
con1.LastName=lastName;
con1.Email=cs.SuppliedEmail;
con1.AccountId='0010W00002MuDcQQAV';
insert con1;
cs.ContactId=con1.Id;
}
}
}
}}}
}}
My test class is
@isTest
public class AutoCreateContactControllerTest {
@isTest
public Static void SpamTestmethod()
{ Account acc = new Account(Name='MassBay');
insert acc;
Contact con = new Contact(AccountId=acc.Id,LastName='test',Email='tttt@test.com');
insert con;
Trigger_Control__c tc=new Trigger_Control__c();
tc.Enable_Auto_Create_contact_Trigger__c=true;
tc.Name='test tc';
insert tc;
List<case>lstcase=new List<case>();
List<RecordType> listRecType = [select Id from RecordType where sObjectType = 'Case' And Name = 'MassBayCC_Ticket'];
Case cs = new Case(RecordTypeId = listRecType[0].Id,AccountId=acc.Id,ContactId=con.Id);
cs.Subject='tesr';
cs.Description='Test description';
cs.SuppliedEmail='tttt@test.com';
cs.SuppliedName='hello world';
lstcase.add(cs);
Case cs1 = new Case(RecordTypeId = listRecType[0].Id,AccountId=acc.Id,ContactId=con.Id);
cs1.Subject='tesr';
cs1.Description='Test Description';
cs1.SuppliedEmail='tttt@test.com';
cs1.SuppliedName='hello world world';
lstcase.add(cs1);
Case cs2 = new Case(RecordTypeId = listRecType[0].Id,AccountId=acc.Id,ContactId=con.Id);
cs2.Subject='tesr';
cs2.Description='Test Description';
cs2.SuppliedEmail='tttt@test.com';
cs2.SuppliedName='hello';
lstcase.add(cs2);
insert lstcase;
}
}
I am facing issue of our test class we only got 13 perent code coverage please help
me
trigger autoCreateContactController on Case (before insert) {
for(Trigger_Control__c tc:Trigger_Control__c.getAll().values())
{
if( tc.Enable_Auto_Create_contact_Trigger__c==true)
{
for(case cs:trigger.new)
{
if(userinfo.getName()=='Automated Workflow'){
contact[] lstcontact= [select id from contact where email=:cs.SuppliedEmail limit 1];
if(!lstcontact.isEmpty())
{
String contId=lstcontact[0].id;
if(contId!=null)
{
cs.ContactId=contId;
}
}
else {
String leftPart = cs.Suppliedname;
String[] leftPartSplitted = leftPart.split('\\s+');
if(leftPart!=null || leftPart!='')
{
if(leftPartSplitted.size() == 3)
{
String firstName = leftPartSplitted[0];
String lastName = leftPartSplitted[1];
String middlename=leftPartSplitted[2];
contact con1 =new contact();
con1.firstname=firstName;
con1.LastName=lastName+middlename;
con1.Email=cs.SuppliedEmail;
con1.AccountId='0010W00002MuDcQQAV';
insert con1;
cs.ContactId=con1.Id;
}
else if(leftPartSplitted.size() == 2)
{
String firstName = leftPartSplitted[0];
String lastName = leftPartSplitted[1];
contact con1 =new contact();
con1.firstname=firstName;
con1.LastName=lastName;
con1.Email=cs.SuppliedEmail;
con1.AccountId='0010W00002MuDcQQAV';
insert con1;
cs.ContactId=con1.Id;
}
else if(leftPartSplitted.size() == 1)
{
String lastName = leftPartSplitted[0];
contact con1 =new contact();
con1.LastName=lastName;
con1.Email=cs.SuppliedEmail;
con1.AccountId='0010W00002MuDcQQAV';
insert con1;
cs.ContactId=con1.Id;
}
}
}
}}}
}}
My test class is
@isTest
public class AutoCreateContactControllerTest {
@isTest
public Static void SpamTestmethod()
{ Account acc = new Account(Name='MassBay');
insert acc;
Contact con = new Contact(AccountId=acc.Id,LastName='test',Email='tttt@test.com');
insert con;
Trigger_Control__c tc=new Trigger_Control__c();
tc.Enable_Auto_Create_contact_Trigger__c=true;
tc.Name='test tc';
insert tc;
List<case>lstcase=new List<case>();
List<RecordType> listRecType = [select Id from RecordType where sObjectType = 'Case' And Name = 'MassBayCC_Ticket'];
Case cs = new Case(RecordTypeId = listRecType[0].Id,AccountId=acc.Id,ContactId=con.Id);
cs.Subject='tesr';
cs.Description='Test description';
cs.SuppliedEmail='tttt@test.com';
cs.SuppliedName='hello world';
lstcase.add(cs);
Case cs1 = new Case(RecordTypeId = listRecType[0].Id,AccountId=acc.Id,ContactId=con.Id);
cs1.Subject='tesr';
cs1.Description='Test Description';
cs1.SuppliedEmail='tttt@test.com';
cs1.SuppliedName='hello world world';
lstcase.add(cs1);
Case cs2 = new Case(RecordTypeId = listRecType[0].Id,AccountId=acc.Id,ContactId=con.Id);
cs2.Subject='tesr';
cs2.Description='Test Description';
cs2.SuppliedEmail='tttt@test.com';
cs2.SuppliedName='hello';
lstcase.add(cs2);
insert lstcase;
}
}
- Sebastian Page
- January 08, 2020
- Like
- 0
Related list quick link component need in lightning community
Hello All,
I have requirment of Related list quick links in lightning community. I am new in lightning admin as well as development so i don't have more knowledge of lightning. Please help me if anyone got solution. I want to same visibility of Related list quick links component in community.
Regards
Sebastian Page
I have requirment of Related list quick links in lightning community. I am new in lightning admin as well as development so i don't have more knowledge of lightning. Please help me if anyone got solution. I want to same visibility of Related list quick links component in community.
Regards
Sebastian Page
- Sebastian Page
- November 18, 2019
- Like
- 0
Some line of apex class is not covered
Hello All
Some line in apex class is not covering please help me.
Some line in apex class is not covering please help me.
public class UpdateAccountManagerEmailAdderss { public Static void updateAccountMgrEmail(List<case> lstcase) { List<String> lstOfDomain=new List<String>(); list <Account> lstAccounts = [Select Id,Account_Manager_Email__c from Account WHERE Old_HD_Provider__c!='ConnectWise' AND Status__c='Live']; Map<String,String>mapAccount=new Map<String,String>(); for(account a:lstAccounts){ mapAccount.put(a.id,a.Account_Manager_Email__c); } Map<string,string> mapDomain=new Map<String,String>(); for(Account ks:[Select id,institutional_EmailDomain__c from Account WHERE Old_HD_Provider__c!='ConnectWise' AND Status__c='Live' and institutional_EmailDomain__c!=null]) { lstOfDomain.add(ks.institutional_EmailDomain__c); mapDomain.put(ks.institutional_EmailDomain__c, ks.id); } for(case cs:lstcase) { if(lstOfDomain.size()>0){ for(String s:lstOfDomain) { if(cs.Description!=null && ( cs.Description).Contains(s)) { cs.AccountId=mapDomain.get(s); cs.Account_Manager_Email__c=mapAccount.get(cs.AccountId); // cs.Identified_Keyword__c=s; } else { if((cs.Description).Contains('Test1ymail')) { cs.Account_Manager_Email__c='Test1ymail'; } if((cs.Description).Contains('Test2ymail')) { cs.Account_Manager_Email__c='Test2ymail'; } if((cs.Description).Contains('Test3ymail')) { cs.Account_Manager_Email__c='Test3ymail'; } } }}}} } test class is @isTest public class UpdateAccountManagerEmailAdderss_Test { @isTest public static void testAcctMgr() { Map<Id,String> mapAccount =new Map<Id,String>(); Map<String,String> mapDomain=new Map<String,String>(); List<string>lstOfDomain=new List<String>(); Account acc =new Account(); acc.name='BlackeBeltHelp Agents'; // acc.Account_Manager_Email__c='test.test@test.com'; acc.Institutional_EmailDomain__c='ben.edu'; insert acc; mapAccount.put(acc.id,acc.Account_Manager_Email__c); mapDomain.put(acc.Institutional_EmailDomain__c,acc.id); lstOfDomain.add(acc.Institutional_EmailDomain__c); Contact con=new Contact(); con.accountId=acc.id; con.firstName='test'; Con.lastName='testcontact'; Con.Email='Shiv@str.tst'; insert con; Trigger_Control__c tc=new Trigger_Control__c(); tc.name='test'; tc.Enable_Update_Account_Mgr_Email_Trigger__c=true; insert tc; List<case>lstcase=new List<case>(); Case cs=new Case(); cs.accountId=acc.id; cs.contactId=con.id; cs.Account_Manager_Email__c=acc.Account_Manager_Email__c; cs.description='kdjksjkfjkjdfsjmk smjkm'; lstcase.add(cs); insert lstcase; UpdateAccountManagerEmailAdderss.updateAccountMgrEmail(lstcase); } }
- Sebastian Page
- July 24, 2019
- Like
- 0
how to create Email-to-case with attachment
Hello All,
I have created web serivce for Email-to-case and enable "Save Email-to-Case attachments as Salesforce Files" but Ticket not created with attachment .
I have created web serivce for Email-to-case and enable "Save Email-to-Case attachments as Salesforce Files" but Ticket not created with attachment .
- Sebastian Page
- April 22, 2019
- Like
- 0
Governing limit Exception error on my batch class
Hi All ,
i am getting error of governing limit error is " System.LimitException: Too many query rows: 50001"
Batch apex class-
global class SSO_User_count implements database.Batchable<sObject> {
global database.QueryLocator start(database.BatchableContext bc)
{
string query='Select id from account';
return database.getQueryLocator(query);
}
global void execute(database.BatchableContext bc ,List<account> scope)
{
List<Account> updateacc=new List<Account>();
list<account> acclist=[select id,SSO_User_Count__c,ispartner ,iscustomerportal from account where Ispartner=true and IsCustomerPortal=true];
for(Account acc:acclist){
List<user>lstusr=[select id FROM User where isActive=true and User.Profile.UserLicense.Name='Overage High Volume Customer Portal' and accountid=:Acc.id];
// acc.SSO_User_Count__c=lstusr.size();
acc.SSO_User_Count__c=lstusr.size();
scope.add(acc);
}
update scope;
}
global void finish(database.BatchableContext bc)
{
}
}
i am getting error of governing limit error is " System.LimitException: Too many query rows: 50001"
Batch apex class-
global class SSO_User_count implements database.Batchable<sObject> {
global database.QueryLocator start(database.BatchableContext bc)
{
string query='Select id from account';
return database.getQueryLocator(query);
}
global void execute(database.BatchableContext bc ,List<account> scope)
{
List<Account> updateacc=new List<Account>();
list<account> acclist=[select id,SSO_User_Count__c,ispartner ,iscustomerportal from account where Ispartner=true and IsCustomerPortal=true];
for(Account acc:acclist){
List<user>lstusr=[select id FROM User where isActive=true and User.Profile.UserLicense.Name='Overage High Volume Customer Portal' and accountid=:Acc.id];
// acc.SSO_User_Count__c=lstusr.size();
acc.SSO_User_Count__c=lstusr.size();
scope.add(acc);
}
update scope;
}
global void finish(database.BatchableContext bc)
{
}
}
- Sebastian Page
- February 06, 2019
- Like
- 0
I am facing issue to write test class
Hi All,
I am facing issue to write test class for this code please help me i am stuck from one month please help me.
public class CommenttoEmail {
public String Commentbody {get;set;}
public String Set_to{get;set;}
Public String Set_bcc{get;set;}
public String Set_cc{get;set;}
public List<String> SetTo {get;set;}
public List<String> SetCC {get;set;}
public List<String> SetBCC{get;set;}
Public String CaseId {get;set;}
public String Selec {get;set;}
public List<String> liststatus {get;set;}
public boolean flag {set;get;}
public string Str2;
public String test;
Public List<string> listall {get;set;}
public Attachment attachment {
get {
if (attachment == null)
attachment = new Attachment();
return attachment;
}
set;
}
public CommenttoEmail(apexpages.StandardController std)
{
liststatus=new List<string>{'New','Escalated','On Hold','Action-Automated Escalation','Agent Research','Scheduled','Awaiting Customer Reply',
'Awaiting External Response','Awaiting Part','Re-Opened','Closed Successful','Closed Unsuccessful'};
flag=false;
CaseId=ApexPages.CurrentPage().getParameters().get('Id');
listall=new List<String>();
SetTo=new List<String>{};
SetCC=new List<String>{};
SetBCC=new List<String>{};
}
public void senttoEmail()
{
Case cse = [select id ,CaseNumber ,Status,ContactEmail,subject from case where id=:caseId];
SetTo=Set_To.split(',');
}
public void bccEmail()
{
SetBCC=Set_bcc.split(',');
}
public void ccEmail()
{
SetCC=Set_cc.split(',');
}
public void ss()
{
senttoEmail();
bccEmail();
ccEmail();
}
public void attachemail()
{
listall.addAll(SetTo);
listall.addAll(SetBCC);
listall.addAll(SetCC);
}
// this method used for creating case comment
public pagereference createCaseComment(){
ss();
upload();
attachemail();
sendingEmail();
ChangeStatus();
Case cse = [select id ,CaseNumber ,Status, Contact.name,Account.name,subject from case where id=:caseId];
String ss=string.join(listall, ',');
String Str1='\n\n';
String Str0='[Recipients:' +ss+']';
String Str3=cse.Contact.name+',\n\n';
String Reg='\n\n\n Sincerely,\n'+cse.Contact.name+'\n'+cse.Account.name;
Str2=Str0+Str1+Str3+Commentbody+Reg;
CaseComment cc = new CaseComment(ParentId = cse.Id,CommentBody = str2 , IsPublished=true);
insert cc;
pagereference pg =new pagereference('/'+CaseId);
return pg;
}
// this method used for sending email
public PageReference sendingEmail()
{
upload();
Case[] cse = [select id ,CaseNumber ,Status, Contact.name,Account.name,subject from case where id=:caseId limit 1];
String ss=string.join(listall, ',');
String Str3=cse[0].Contact.name+',\n\n';
String Reg='\n\n\n Sincerely,\n'+cse[0].Contact.name+'\n'+cse[0].Account.name;
Str2=Str3+Commentbody+Reg;
List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
List<Attachment> Attlist=[select Name, Body, BodyLength from Attachment where ParentId = :caseId];
for (Attachment a :Attlist ){
Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
efa.setFileName(a.Name);
efa.setBody(a.Body);
fileAttachments.add(efa);
}
try{
Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
semail.setToAddresses(SetTo);
semail.setBccAddresses(SetBCC);
semail.setCcAddresses(SetCC);
semail.setSubject(cse[0].Subject);
semail.setPlainTextBody(Str2);
semail.setFileAttachments(fileAttachments);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {semail});
}catch(exception e)
{}
return null;
}
//This method use for redirect to current ticket.
public pagereference redirectCasePage()
{
CaseId=ApexPages.CurrentPage().getParameters().get('Id');
pagereference pg =new pagereference('/'+CaseId);
return pg;
}
//This Method used for change status
public void ChangeStatus()
{
List<Case> cse = [select id ,CaseNumber ,Status,subject from case where id=:caseId];
for(Case c:cse){
if(selec=='New')
{
c.Status='New';
}
if(selec=='Escalated')
{
c.Status='Escalated';
}
if(selec=='On Hold')
{
c.Status='On Hold';
}
if(selec=='Action-Automated Escalation')
{
c.Status='Action-Automated Escalation';
}
if(selec=='Agent Research')
{
c.Status='Agent Research';
}
if(selec=='Scheduled')
{
c.Status='Scheduled';
}
if(selec=='Action-Automated Escalation')
{
c.Status='Action-Automated Escalation';
}
if(selec=='Awaiting Customer Reply')
{
c.Status='Awaiting Customer Reply';
}
if(selec=='Awaiting External Response')
{
c.Status='Awaiting External Response';
}
if(selec=='Awaiting Part')
{
c.Status='Awaiting Part';
}if(selec=='Re-Opened')
{
c.Status='Re-Opened';
}if(selec=='Closed Successful')
{
c.Status='Closed Successful';
}if(selec=='Closed Unsuccessful')
{
c.Status='Closed Unsuccessful';
}
update c;
}
}
// This Method create for status display in custom picklist
public List<SelectOption> getCaseStatus()
{
List<SelectOption> optlist=new List<SelectOption>();
Case[] cse = [select id ,CaseNumber ,Status,subject from case where id=:caseId limit 1];
optlist.add(new SelectOption(cse[0].Status,cse[0].Status));
for(String s:liststatus)
{
optlist.add(new SelectOption(s,s));
}
return optlist;
}
//This Method Created for uploading file
public PageReference upload() {
attachment.OwnerId = UserInfo.getUserId();
attachment.ParentId = CaseId;
attachment.IsPrivate = true;
attachment.ContentType = 'image/jpeg';
try {
insert attachment;
} catch (DMLException e) {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
return null;
} finally {
attachment = new Attachment();
}
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Attachment uploaded successfully'));
return null;
}
}
I am facing issue to write test class for this code please help me i am stuck from one month please help me.
public class CommenttoEmail {
public String Commentbody {get;set;}
public String Set_to{get;set;}
Public String Set_bcc{get;set;}
public String Set_cc{get;set;}
public List<String> SetTo {get;set;}
public List<String> SetCC {get;set;}
public List<String> SetBCC{get;set;}
Public String CaseId {get;set;}
public String Selec {get;set;}
public List<String> liststatus {get;set;}
public boolean flag {set;get;}
public string Str2;
public String test;
Public List<string> listall {get;set;}
public Attachment attachment {
get {
if (attachment == null)
attachment = new Attachment();
return attachment;
}
set;
}
public CommenttoEmail(apexpages.StandardController std)
{
liststatus=new List<string>{'New','Escalated','On Hold','Action-Automated Escalation','Agent Research','Scheduled','Awaiting Customer Reply',
'Awaiting External Response','Awaiting Part','Re-Opened','Closed Successful','Closed Unsuccessful'};
flag=false;
CaseId=ApexPages.CurrentPage().getParameters().get('Id');
listall=new List<String>();
SetTo=new List<String>{};
SetCC=new List<String>{};
SetBCC=new List<String>{};
}
public void senttoEmail()
{
Case cse = [select id ,CaseNumber ,Status,ContactEmail,subject from case where id=:caseId];
SetTo=Set_To.split(',');
}
public void bccEmail()
{
SetBCC=Set_bcc.split(',');
}
public void ccEmail()
{
SetCC=Set_cc.split(',');
}
public void ss()
{
senttoEmail();
bccEmail();
ccEmail();
}
public void attachemail()
{
listall.addAll(SetTo);
listall.addAll(SetBCC);
listall.addAll(SetCC);
}
// this method used for creating case comment
public pagereference createCaseComment(){
ss();
upload();
attachemail();
sendingEmail();
ChangeStatus();
Case cse = [select id ,CaseNumber ,Status, Contact.name,Account.name,subject from case where id=:caseId];
String ss=string.join(listall, ',');
String Str1='\n\n';
String Str0='[Recipients:' +ss+']';
String Str3=cse.Contact.name+',\n\n';
String Reg='\n\n\n Sincerely,\n'+cse.Contact.name+'\n'+cse.Account.name;
Str2=Str0+Str1+Str3+Commentbody+Reg;
CaseComment cc = new CaseComment(ParentId = cse.Id,CommentBody = str2 , IsPublished=true);
insert cc;
pagereference pg =new pagereference('/'+CaseId);
return pg;
}
// this method used for sending email
public PageReference sendingEmail()
{
upload();
Case[] cse = [select id ,CaseNumber ,Status, Contact.name,Account.name,subject from case where id=:caseId limit 1];
String ss=string.join(listall, ',');
String Str3=cse[0].Contact.name+',\n\n';
String Reg='\n\n\n Sincerely,\n'+cse[0].Contact.name+'\n'+cse[0].Account.name;
Str2=Str3+Commentbody+Reg;
List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
List<Attachment> Attlist=[select Name, Body, BodyLength from Attachment where ParentId = :caseId];
for (Attachment a :Attlist ){
Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
efa.setFileName(a.Name);
efa.setBody(a.Body);
fileAttachments.add(efa);
}
try{
Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
semail.setToAddresses(SetTo);
semail.setBccAddresses(SetBCC);
semail.setCcAddresses(SetCC);
semail.setSubject(cse[0].Subject);
semail.setPlainTextBody(Str2);
semail.setFileAttachments(fileAttachments);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {semail});
}catch(exception e)
{}
return null;
}
//This method use for redirect to current ticket.
public pagereference redirectCasePage()
{
CaseId=ApexPages.CurrentPage().getParameters().get('Id');
pagereference pg =new pagereference('/'+CaseId);
return pg;
}
//This Method used for change status
public void ChangeStatus()
{
List<Case> cse = [select id ,CaseNumber ,Status,subject from case where id=:caseId];
for(Case c:cse){
if(selec=='New')
{
c.Status='New';
}
if(selec=='Escalated')
{
c.Status='Escalated';
}
if(selec=='On Hold')
{
c.Status='On Hold';
}
if(selec=='Action-Automated Escalation')
{
c.Status='Action-Automated Escalation';
}
if(selec=='Agent Research')
{
c.Status='Agent Research';
}
if(selec=='Scheduled')
{
c.Status='Scheduled';
}
if(selec=='Action-Automated Escalation')
{
c.Status='Action-Automated Escalation';
}
if(selec=='Awaiting Customer Reply')
{
c.Status='Awaiting Customer Reply';
}
if(selec=='Awaiting External Response')
{
c.Status='Awaiting External Response';
}
if(selec=='Awaiting Part')
{
c.Status='Awaiting Part';
}if(selec=='Re-Opened')
{
c.Status='Re-Opened';
}if(selec=='Closed Successful')
{
c.Status='Closed Successful';
}if(selec=='Closed Unsuccessful')
{
c.Status='Closed Unsuccessful';
}
update c;
}
}
// This Method create for status display in custom picklist
public List<SelectOption> getCaseStatus()
{
List<SelectOption> optlist=new List<SelectOption>();
Case[] cse = [select id ,CaseNumber ,Status,subject from case where id=:caseId limit 1];
optlist.add(new SelectOption(cse[0].Status,cse[0].Status));
for(String s:liststatus)
{
optlist.add(new SelectOption(s,s));
}
return optlist;
}
//This Method Created for uploading file
public PageReference upload() {
attachment.OwnerId = UserInfo.getUserId();
attachment.ParentId = CaseId;
attachment.IsPrivate = true;
attachment.ContentType = 'image/jpeg';
try {
insert attachment;
} catch (DMLException e) {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
return null;
} finally {
attachment = new Attachment();
}
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Attachment uploaded successfully'));
return null;
}
}
- Sebastian Page
- November 29, 2018
- Like
- 0
Need help on Test class and code coverage
Hello All, I am facing issue on test class. My test class execute successfully but code coverage is None please Help.
My apex class here
@istest
public class CommenttoEmailTest {
static testMethod void testMatching(){
// Id rtId = [select Id, name from RecordType where name = 'Massbay_Ticket' and SObjectType = 'Case' limit 1].Id;
//create account
Account acc = new Account();
//enter details
acc.Name = 'Test Account';
//Add other fields
insert acc;
// create test contact
Contact con = TestUtilityController.getContact('Test Last Name','testing@testing.com',acc.Id);
insert con;
// Create test cases
List<Case> listCase = new List<Case>();
if(UtilityController.caseRecordType.containsKey('Massbay_Ticket')){
String recordTypeId = UtilityController.caseRecordType.get('Massbay_Ticket').Id;
Case csa = TestUtilityController.getCase(recordTypeId,con.Id,acc.Id);
//enter details
//Add other fields
csa.Ticket_Category__c='Blackboard learn';
csa.Status = 'Action-Automated Escalation';
insert csa;
PageReference pageRef = Page.MyNew_commentvf;
pageRef.getParameters().put(recordTypeId, String.valueOf(csa.Id));
Test.setCurrentPage(pageRef);
CaseComment tComment = new CaseComment();
tComment.ParentId = Csa.Id;
tComment.CommentBody = 'Some Comment';
tComment.IsPublished = TRUE;
insert tComment;
tComment.CommentBody = 'Inporgreess Comment';
update tComment ;
ApexPages.StandardController sc = new ApexPages.StandardController(csa);
CommenttoEmail testCmEmail = new CommenttoEmail (sc);
testCmEmail.senttoEmail();
testCmEmail.bccEmail();
testCmEmail.ccEmail();
testCmEmail.attachemail();
testCmEmail.createCaseComment();
testCmEmail.sendingEmail();
testCmEmail.ss();
testCmEmail.ChangeStatus();
testCmEmail.getCaseStatus();
testCmEmail.upload();
}
}// end of test method
}// end of Class
and my test class is
@istest
public class CommenttoEmailTest {
static testMethod void testMatching(){
// Id rtId = [select Id, name from RecordType where name = 'Massbay_Ticket' and SObjectType = 'Case' limit 1].Id;
//create account
Account acc = new Account();
//enter details
acc.Name = 'Test Account';
//Add other fields
insert acc;
// create test contact
Contact con = TestUtilityController.getContact('Test Last Name','testing@testing.com',acc.Id);
insert con;
// Create test cases
List<Case> listCase = new List<Case>();
if(UtilityController.caseRecordType.containsKey('Massbay_Ticket')){
String recordTypeId = UtilityController.caseRecordType.get('Massbay_Ticket').Id;
Case csa = TestUtilityController.getCase(recordTypeId,con.Id,acc.Id);
//enter details
//Add other fields
csa.Ticket_Category__c='Blackboard learn';
csa.Status = 'Action-Automated Escalation';
insert csa;
PageReference pageRef = Page.MyNew_commentvf;
pageRef.getParameters().put(recordTypeId, String.valueOf(csa.Id));
Test.setCurrentPage(pageRef);
CaseComment tComment = new CaseComment();
tComment.ParentId = Csa.Id;
tComment.CommentBody = 'Some Comment';
tComment.IsPublished = TRUE;
insert tComment;
tComment.CommentBody = 'Inporgreess Comment';
update tComment ;
ApexPages.StandardController sc = new ApexPages.StandardController(csa);
CommenttoEmail testCmEmail = new CommenttoEmail (sc);
testCmEmail.senttoEmail();
testCmEmail.bccEmail();
testCmEmail.ccEmail();
testCmEmail.attachemail();
testCmEmail.createCaseComment();
testCmEmail.sendingEmail();
testCmEmail.ss();
testCmEmail.ChangeStatus();
testCmEmail.getCaseStatus();
testCmEmail.upload();
}
}// end of test method
}// end of Class
My apex class here
@istest
public class CommenttoEmailTest {
static testMethod void testMatching(){
// Id rtId = [select Id, name from RecordType where name = 'Massbay_Ticket' and SObjectType = 'Case' limit 1].Id;
//create account
Account acc = new Account();
//enter details
acc.Name = 'Test Account';
//Add other fields
insert acc;
// create test contact
Contact con = TestUtilityController.getContact('Test Last Name','testing@testing.com',acc.Id);
insert con;
// Create test cases
List<Case> listCase = new List<Case>();
if(UtilityController.caseRecordType.containsKey('Massbay_Ticket')){
String recordTypeId = UtilityController.caseRecordType.get('Massbay_Ticket').Id;
Case csa = TestUtilityController.getCase(recordTypeId,con.Id,acc.Id);
//enter details
//Add other fields
csa.Ticket_Category__c='Blackboard learn';
csa.Status = 'Action-Automated Escalation';
insert csa;
PageReference pageRef = Page.MyNew_commentvf;
pageRef.getParameters().put(recordTypeId, String.valueOf(csa.Id));
Test.setCurrentPage(pageRef);
CaseComment tComment = new CaseComment();
tComment.ParentId = Csa.Id;
tComment.CommentBody = 'Some Comment';
tComment.IsPublished = TRUE;
insert tComment;
tComment.CommentBody = 'Inporgreess Comment';
update tComment ;
ApexPages.StandardController sc = new ApexPages.StandardController(csa);
CommenttoEmail testCmEmail = new CommenttoEmail (sc);
testCmEmail.senttoEmail();
testCmEmail.bccEmail();
testCmEmail.ccEmail();
testCmEmail.attachemail();
testCmEmail.createCaseComment();
testCmEmail.sendingEmail();
testCmEmail.ss();
testCmEmail.ChangeStatus();
testCmEmail.getCaseStatus();
testCmEmail.upload();
}
}// end of test method
}// end of Class
and my test class is
@istest
public class CommenttoEmailTest {
static testMethod void testMatching(){
// Id rtId = [select Id, name from RecordType where name = 'Massbay_Ticket' and SObjectType = 'Case' limit 1].Id;
//create account
Account acc = new Account();
//enter details
acc.Name = 'Test Account';
//Add other fields
insert acc;
// create test contact
Contact con = TestUtilityController.getContact('Test Last Name','testing@testing.com',acc.Id);
insert con;
// Create test cases
List<Case> listCase = new List<Case>();
if(UtilityController.caseRecordType.containsKey('Massbay_Ticket')){
String recordTypeId = UtilityController.caseRecordType.get('Massbay_Ticket').Id;
Case csa = TestUtilityController.getCase(recordTypeId,con.Id,acc.Id);
//enter details
//Add other fields
csa.Ticket_Category__c='Blackboard learn';
csa.Status = 'Action-Automated Escalation';
insert csa;
PageReference pageRef = Page.MyNew_commentvf;
pageRef.getParameters().put(recordTypeId, String.valueOf(csa.Id));
Test.setCurrentPage(pageRef);
CaseComment tComment = new CaseComment();
tComment.ParentId = Csa.Id;
tComment.CommentBody = 'Some Comment';
tComment.IsPublished = TRUE;
insert tComment;
tComment.CommentBody = 'Inporgreess Comment';
update tComment ;
ApexPages.StandardController sc = new ApexPages.StandardController(csa);
CommenttoEmail testCmEmail = new CommenttoEmail (sc);
testCmEmail.senttoEmail();
testCmEmail.bccEmail();
testCmEmail.ccEmail();
testCmEmail.attachemail();
testCmEmail.createCaseComment();
testCmEmail.sendingEmail();
testCmEmail.ss();
testCmEmail.ChangeStatus();
testCmEmail.getCaseStatus();
testCmEmail.upload();
}
}// end of test method
}// end of Class
- Sebastian Page
- November 20, 2018
- Like
- 0
How to identify article attached to a case using apex?
Hi,
Can anyone please tell me how to identify an article is attached to case using apex using Apex?
Please note that the case is not opened in the edit mode.
Thanks in advance!
Best Regards,
Nivea
Can anyone please tell me how to identify an article is attached to case using apex using Apex?
Please note that the case is not opened in the edit mode.
Thanks in advance!
Best Regards,
Nivea
- Nivea Nair
- July 05, 2016
- Like
- 0