-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
4Questions
-
1Replies
I can't able to understand why code coverage is showing only 53% for below mentioned class
I can't able to understand why code coverage is showing only 53% for below mentioned class
Class :-
public class PIREmailNotifcation {
final static string className = 'PIREmailNotifcation';
public static void MasterCaseEmail(list<case>caselist){
try{
for (case caserecord:caselist){
if( caserecord.Master_Case__c==True && caserecord.RFO_Available__c==True){
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
OrgWideEmailAddress[] owea = [select Id from OrgWideEmailAddress where Address = 'customerservicesupport-uat@mitel.com'];
system.debug('@@@@'+owea);
// string templatelabel = Label.PIRExternalEmailTemplate;
// Map<String,PIRInternalEMailIds__c> allemail = PIRInternalEMailIds__c.getAll();
//PIRInternalEMailIds__c cs = PIRInternalEMailIds__c.getAll();
String[] toAddresses = new String[] {(caserecord.ContactEmail)};
mail.setToAddresses(toAddresses);
mail.whatid=caserecord.Id;
mail.setTargetObjectId(caserecord.ContactId);
mail.setReplyTo('aloke.singh90@gmail.com');
mail.setUseSignature(false);
mail.setTemplateId('00XC0000001R6IW');
mail.saveAsActivity = True;
mail.setOrgWideEmailAddressId(owea.get(0).Id);
PIR__c[] pirid=[select Id,MasterCase_ID__c from PIR__c where MasterCase_ID__c =: caserecord.Id];
system.debug('%%%%pirid%%%'+pirid);
List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
for(Attachment a : [select Name, Body, BodyLength from Attachment where ParentId = :pirid.get(0).Id]){
Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
efa.setFileName(a.Name);
efa.setBody(a.Body);
fileAttachments.add(efa);
}
mail.setFileAttachments(fileAttachments);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
}
catch(exception me){HandlerUtility.trackException(me, className);
}
}
public static void childCaseEMail(list<case>childcase){
try{
//if(pirtriggerboolean.runOnce()){
// pirtriggerboolean.iteration= false;
set<Id> caseId = new set<Id>();
set<Id> contactId = new set<Id>();
for(case caserecord:childcase){
if(caserecord.CaseNumber != null ){
caseId.add(caserecord.Id);
}
}
//system.debug('$$$$$'+childcaseId);
Case[] childcaseId = [SELECT CaseNumber, AccountId, Id, ContactId, Subject, Description, ContactEmail, contact.name, ParentId,
SuppliedEmail FROM Case WHERE ParentId=:caseId];
system.debug('$$$$$'+childcaseId);
Map<Id,String> ContactEmail = new Map<Id, String>();
Map<Id, String> ContactFirstname = new Map<Id, String>();
for(case c:childcaseId){
contactId.add(c.ContactId);
}
list<contact> conList=[select id, email from Contact where id IN :contactId];
system.debug('$$$$$'+conList);
if(conList.size() !=null){
for(Contact c2:conList)
ContactEmail.put(c2.id,c2.email);
}
for(case childrecord :childcaseId){
for(contact cont:conList){
if(childrecord.ContactId == cont.Id ){
//string templatelabel = Label.PIRExternalEmailTemplate;
PIR__c [] pirrecordId=[select Id,MasterCase_ID__c from PIR__c where MasterCase_ID__c IN: caseId];
system.debug('$$$$$'+pirrecordId);
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
OrgWideEmailAddress[] owea = [select Id from OrgWideEmailAddress where Address = 'customerservicesupport-uat@mitel.com'];
system.debug('@@@@'+owea);
String[] toAddresses = new String[] {ContactEmail.get(cont.id)};
mail.setToAddresses(toAddresses);
mail.whatid=childrecord.Id;
mail.setTargetObjectId(childrecord.ContactId);
mail.setReplyTo('aloke.singh90@gmail.com');
mail.setUseSignature(false);
mail.setTemplateId('00X4F000000gs6W');
mail.saveAsActivity = True;
mail.setOrgWideEmailAddressId(owea.get(0).Id);
List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
for(Attachment a : [select Name, Body, BodyLength from Attachment where ParentId = :pirrecordId.get(0).Id]){
Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
efa.setFileName(a.Name);
efa.setBody(a.Body);
fileAttachments.add(efa);
}
mail.setFileAttachments(fileAttachments);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
}
// }
}
catch (exception me){HandlerUtility.trackException(me, className);
}
}
}
Test Class :-
@isTest
public class PIREmailNotifcationTest {
static{
TestDataUtility.utilityTestData();
}
static testmethod void testemailsent(){
Contact con = new Contact();
con.firstname = 'test';
con.lastname = 'test';
con.email = 'test@example.com';
insert con;
Case caserecord = TestDataUtility.CreateTestCase();
caserecord.Master_Case__c =TRUE;
caserecord.RFO_Available__c =TRUE;
caserecord.contactid = con.id;
insert caserecord;
Case ccase = TestDataUtility.createtestcase();
ccase.parentid = caserecord.id;
ccase.contactid = con.id;
PIR__c pirrecord = new PIR__c();
pirrecord.Name = '12345';
pirrecord.CurrencyIsoCode='USD';
pirrecord.MasterCase_ID__c=caserecord.Id;
insert pirrecord;
Attachment myAttachment = new Attachment();
myAttachment.Body= Blob.valueOf('Test Attachment Body');
myAttachment.ParentId= pirrecord.Id;
myAttachment.Name='ABC';
insert myAttachment;
system.debug ('BodyLength::'+ myattachment.BodyLength);
caserecord.Master_Case__c =TRUE;
caserecord.RFO_Available__c =TRUE;
update caserecord;
/* List<Attachment> att = [Select id from attachment where parentid =: pirrecord.id];
System.assertEquals(1, att.size());
EmailMessage outGoingMail= new EmailMessage();
outGoingMail.fromaddress='test@test.com';
outGoingMail.toAddress = 'con1.Email';
outGoingMail.subject = 'Opt Out Test Message';
outGoingMail.TextBody= 'This is the message body BR-Interno.';
outGOingMail.ParentID = caserecord.id;
insert outGoingMail; */
}
}
Class :-
public class PIREmailNotifcation {
final static string className = 'PIREmailNotifcation';
public static void MasterCaseEmail(list<case>caselist){
try{
for (case caserecord:caselist){
if( caserecord.Master_Case__c==True && caserecord.RFO_Available__c==True){
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
OrgWideEmailAddress[] owea = [select Id from OrgWideEmailAddress where Address = 'customerservicesupport-uat@mitel.com'];
system.debug('@@@@'+owea);
// string templatelabel = Label.PIRExternalEmailTemplate;
// Map<String,PIRInternalEMailIds__c> allemail = PIRInternalEMailIds__c.getAll();
//PIRInternalEMailIds__c cs = PIRInternalEMailIds__c.getAll();
String[] toAddresses = new String[] {(caserecord.ContactEmail)};
mail.setToAddresses(toAddresses);
mail.whatid=caserecord.Id;
mail.setTargetObjectId(caserecord.ContactId);
mail.setReplyTo('aloke.singh90@gmail.com');
mail.setUseSignature(false);
mail.setTemplateId('00XC0000001R6IW');
mail.saveAsActivity = True;
mail.setOrgWideEmailAddressId(owea.get(0).Id);
PIR__c[] pirid=[select Id,MasterCase_ID__c from PIR__c where MasterCase_ID__c =: caserecord.Id];
system.debug('%%%%pirid%%%'+pirid);
List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
for(Attachment a : [select Name, Body, BodyLength from Attachment where ParentId = :pirid.get(0).Id]){
Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
efa.setFileName(a.Name);
efa.setBody(a.Body);
fileAttachments.add(efa);
}
mail.setFileAttachments(fileAttachments);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
}
catch(exception me){HandlerUtility.trackException(me, className);
}
}
public static void childCaseEMail(list<case>childcase){
try{
//if(pirtriggerboolean.runOnce()){
// pirtriggerboolean.iteration= false;
set<Id> caseId = new set<Id>();
set<Id> contactId = new set<Id>();
for(case caserecord:childcase){
if(caserecord.CaseNumber != null ){
caseId.add(caserecord.Id);
}
}
//system.debug('$$$$$'+childcaseId);
Case[] childcaseId = [SELECT CaseNumber, AccountId, Id, ContactId, Subject, Description, ContactEmail, contact.name, ParentId,
SuppliedEmail FROM Case WHERE ParentId=:caseId];
system.debug('$$$$$'+childcaseId);
Map<Id,String> ContactEmail = new Map<Id, String>();
Map<Id, String> ContactFirstname = new Map<Id, String>();
for(case c:childcaseId){
contactId.add(c.ContactId);
}
list<contact> conList=[select id, email from Contact where id IN :contactId];
system.debug('$$$$$'+conList);
if(conList.size() !=null){
for(Contact c2:conList)
ContactEmail.put(c2.id,c2.email);
}
for(case childrecord :childcaseId){
for(contact cont:conList){
if(childrecord.ContactId == cont.Id ){
//string templatelabel = Label.PIRExternalEmailTemplate;
PIR__c [] pirrecordId=[select Id,MasterCase_ID__c from PIR__c where MasterCase_ID__c IN: caseId];
system.debug('$$$$$'+pirrecordId);
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
OrgWideEmailAddress[] owea = [select Id from OrgWideEmailAddress where Address = 'customerservicesupport-uat@mitel.com'];
system.debug('@@@@'+owea);
String[] toAddresses = new String[] {ContactEmail.get(cont.id)};
mail.setToAddresses(toAddresses);
mail.whatid=childrecord.Id;
mail.setTargetObjectId(childrecord.ContactId);
mail.setReplyTo('aloke.singh90@gmail.com');
mail.setUseSignature(false);
mail.setTemplateId('00X4F000000gs6W');
mail.saveAsActivity = True;
mail.setOrgWideEmailAddressId(owea.get(0).Id);
List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
for(Attachment a : [select Name, Body, BodyLength from Attachment where ParentId = :pirrecordId.get(0).Id]){
Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
efa.setFileName(a.Name);
efa.setBody(a.Body);
fileAttachments.add(efa);
}
mail.setFileAttachments(fileAttachments);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
}
// }
}
catch (exception me){HandlerUtility.trackException(me, className);
}
}
}
Test Class :-
@isTest
public class PIREmailNotifcationTest {
static{
TestDataUtility.utilityTestData();
}
static testmethod void testemailsent(){
Contact con = new Contact();
con.firstname = 'test';
con.lastname = 'test';
con.email = 'test@example.com';
insert con;
Case caserecord = TestDataUtility.CreateTestCase();
caserecord.Master_Case__c =TRUE;
caserecord.RFO_Available__c =TRUE;
caserecord.contactid = con.id;
insert caserecord;
Case ccase = TestDataUtility.createtestcase();
ccase.parentid = caserecord.id;
ccase.contactid = con.id;
PIR__c pirrecord = new PIR__c();
pirrecord.Name = '12345';
pirrecord.CurrencyIsoCode='USD';
pirrecord.MasterCase_ID__c=caserecord.Id;
insert pirrecord;
Attachment myAttachment = new Attachment();
myAttachment.Body= Blob.valueOf('Test Attachment Body');
myAttachment.ParentId= pirrecord.Id;
myAttachment.Name='ABC';
insert myAttachment;
system.debug ('BodyLength::'+ myattachment.BodyLength);
caserecord.Master_Case__c =TRUE;
caserecord.RFO_Available__c =TRUE;
update caserecord;
/* List<Attachment> att = [Select id from attachment where parentid =: pirrecord.id];
System.assertEquals(1, att.size());
EmailMessage outGoingMail= new EmailMessage();
outGoingMail.fromaddress='test@test.com';
outGoingMail.toAddress = 'con1.Email';
outGoingMail.subject = 'Opt Out Test Message';
outGoingMail.TextBody= 'This is the message body BR-Interno.';
outGOingMail.ParentID = caserecord.id;
insert outGoingMail; */
}
}
- Aloke Singh 6
- January 09, 2020
- Like
- 0
I am getting the below error :-System.QueryException: Inline query has too many rows for direct assignment, use FOR loop
I am new to salesforce and getting below mentioned exception in one of the query :-
public static void buildPartnerTeam (list<SObject> objects)
{
FINAL list<String> roleNames = new list<String>
{
'Account Partner',
'Account Partner Parent',
'Account Partner Manager To Self',
'Account Partner User To Self',
'Account Partner Manager',
'Account Master Agent', // jul 17
'Account- Sub Agent Super User Access Customer (Authorized)', // jul 17
'Account- Sub Agent Super User Access to Prospect or Customer (Unauthorized)', // jul 17
'Account Related Partner Contact' // MO-66
};
list<Partner_Team_Member__c> ptmsToInsert = new list<Partner_Team_Member__c>{};
map<Id,Account> partnerAccountsMap = new map<Id,Account>{};
list<Id> partnerAccountIds = new list<Id>{};
list<Partner_Team_Role__c> partnerTeamRoles = TransactionSupport.getPartnerTeamRoles (roleNames);
// list<Partner_Team_Role__c> partnerTeamRoles = [SELECT Id, Unique_Name__c FROM Partner_Team_Role__c WHERE Unique_Name__c IN :roleNames];
list<Id> accountIds = new list<Id>{};
for (SObject o : objects)
{
if (o.get('Partner_Account__c') != null) partnerAccountIds.add ((Id) o.get('Partner_Account__c'));
if (o.get('CSD_MA__c') != null) partnerAccountIds.add ((Id) o.get('CSD_MA__c'));
if (o.get('Partner_Of_Record_Cloud__c') != null) partnerAccountIds.add ((Id) o.get('Partner_Of_Record_Cloud__c'));
accountids.add (o.Id);
}
// MO-66: get AccountContactRelations
map<Id,Account> accountsWithACRsMap = new map<Id,Account>([SELECT Id,(SELECT Id, ContactId, AccountId FROM AccountContactRelations)
FROM Account WHERE Id IN :accountIds]); //This is line where I am getting this error
// system.debug('&&&'+accountsWithACRsMap);
map<Id,Id> contactToUserIdsMap = new map<Id,Id>{};
set<Id> contactIds = new set<Id>{};
// list<Account> acc = [SELECT Id,(SELECT Id, ContactId, AccountId FROM AccountContactRelations)
// FROM Account WHERE Id IN :accountIds];
// accId = accountsWithACRsMap.values();
/* for(Account acct : acc) {
system.debug('&&&'+acct);
integer count=0;
for (AccountContactRelation acr : acct.AccountContactRelations)
{
count++;
if (acr.AccountId != acct.Id) contactIds.add (acr.ContactId);
}
} */
for (Account a : accountsWithACRsMap.values())
{
for (AccountContactRelation acr : a.AccountContactRelations)
{
if (acr.AccountId != a.Id) contactIds.add (acr.ContactId);
}
}
/* for (Account a : acc)
{
for (AccountContactRelation acr : a.AccountContactRelations)
{
if (acr.AccountId != a.Id) contactIds.add (acr.ContactId);
}
} */
// MO-66: build map for Contact Id to User Id, for all AccountContactRelation records
for (User u : [SELECT Id, ContactId FROM User WHERE ContactId IN :contactIds])
{
contactToUserIdsMap.put (u.ContactId, u.Id);
}
// now add partner team members
for (Account a : [SELECT Id, Type, Partner_Account__c, ParentId, Partner_Type__c,
Sub_Agent_Authorized_to_access_cases__c
FROM Account
WHERE Id IN :partnerAccountIds])
{
partnerAccountsMap.put (a.Id, a);
}
for (SObject o : objects)
{
for (Partner_Team_Role__c ptr : partnerTeamRoles)
{
if (ptr.Unique_Name__c == roleNames[0] || // 'Account Partner'
ptr.Unique_Name__c == roleNames[4]) // 'Account Partner Manager'
{
Id lookupId = (Id) o.get ('Partner_Account__c');
if (lookupId != null)
{
Partner_Team_Member__c ptm = new Partner_Team_Member__c (Partner_Team_Role__c = ptr.Id,
Partner_Account__c = lookupId,
Reason__c = 'Automatic');
ptm.put ('Account__c', o.Id);
ptmsToInsert.add (ptm);
}
lookupId = (Id) o.get ('Partner_Of_Record_Cloud__c');
if (lookupId != null)
{
Account partnerAccount = partnerAccountsMap.get (lookupId);
if (partnerAccount.Partner_Type__c != 'Sub-Agent') // jul 17
{
Partner_Team_Member__c ptm = new Partner_Team_Member__c (Partner_Team_Role__c = ptr.Id,
Partner_Account__c = lookupId,
Reason__c = 'Automatic');
ptm.put ('Account__c', o.Id);
ptmsToInsert.add (ptm);
}
}
}
if (ptr.Unique_Name__c == roleNames[1]) // 'Account Partner Parent'
{
Account a = partnerAccountsMap.get ((Id) o.get ('Partner_Account__c'));
if (a != null)
{
if (a.Partner_Account__c != null)
{
Partner_Team_Member__c ptm = new Partner_Team_Member__c (Partner_Team_Role__c = ptr.Id,
Partner_Account__c = a.Partner_Account__c,
Reason__c = 'Automatic');
ptm.put ('Account__c', o.Id);
ptmsToInsert.add (ptm);
}
if (a.ParentId != null)
{
Partner_Team_Member__c ptm = new Partner_Team_Member__c (Partner_Team_Role__c = ptr.Id,
Partner_Account__c = a.ParentId,
Reason__c = 'Automatic');
ptm.put ('Account__c', o.Id);
ptmsToInsert.add (ptm);
}
}
Id lookupId = (Id) o.get ('ParentId');
if (lookupId != null)
{
Partner_Team_Member__c ptm = new Partner_Team_Member__c (Partner_Team_Role__c = ptr.Id,
Partner_Account__c = lookupId,
Reason__c = 'Automatic');
ptm.put ('Account__c', o.Id);
ptmsToInsert.add (ptm);
}
}
// 'Account Partner Manager To Self' or 'Account Partner User To Self'
if ((String) o.get('Type') == 'Partner' && (ptr.Unique_Name__c == roleNames[2] || ptr.Unique_Name__c == roleNames[3]))
{
Partner_Team_Member__c ptm = new Partner_Team_Member__c (Partner_Team_Role__c = ptr.Id,
Partner_Account__c = o.Id,
Reason__c = 'Automatic');
ptm.put ('Account__c', o.Id);
ptmsToInsert.add (ptm);
}
if (ptr.Unique_Name__c == roleNames[5]) // 'Account Master Agent' // Jul 17
{
Id lookupId = (Id) o.get ('CSD_MA__c');
if (lookupId != null)
{
Partner_Team_Member__c ptm = new Partner_Team_Member__c (Partner_Team_Role__c = ptr.Id,
Partner_Account__c = lookupId,
Reason__c = 'Automatic');
ptm.put ('Account__c', o.Id);
ptmsToInsert.add (ptm);
}
}
if (ptr.Unique_Name__c == roleNames[6]) // 'Account- Sub Agent Super User Access Customer (Authorized)' // Jul 17
{
Id lookupId = (Id) o.get ('Partner_Of_Record_Cloud__c');
if (lookupId != null)
{
Account partnerAccount = partnerAccountsMap.get (lookupId);
if (partnerAccount.Partner_Type__c == 'Sub-Agent' &&
partnerAccount.Sub_Agent_Authorized_to_access_cases__c == true) // jul 17
{
Partner_Team_Member__c ptm = new Partner_Team_Member__c (Partner_Team_Role__c = ptr.Id,
Partner_Account__c = lookupId,
Reason__c = 'Automatic');
ptm.put ('Account__c', o.Id);
ptmsToInsert.add (ptm);
}
}
}
if (ptr.Unique_Name__c == roleNames[7]) // 'Account- Sub Agent Super User Access to Prospect or Customer (Unauthorized)' // jul 17
{
Id lookupId = (Id) o.get ('Partner_Of_Record_Cloud__c');
if (lookupId != null)
{
Account partnerAccount = partnerAccountsMap.get (lookupId);
if (partnerAccount.Partner_Type__c == 'Sub-Agent' &&
partnerAccount.Sub_Agent_Authorized_to_access_cases__c == false) // jul 17
{
Partner_Team_Member__c ptm = new Partner_Team_Member__c (Partner_Team_Role__c = ptr.Id,
Partner_Account__c = lookupId,
Reason__c = 'Automatic');
ptm.put ('Account__c', o.Id);
ptmsToInsert.add (ptm);
}
}
}
// MO-66: Add PTMs for all Related Contacts
if (ptr.Unique_Name__c == roleNames[8]) // 'Account Related Partner Contact'
{
Account accountWithACRs = accountsWithACRsMap.get (o.Id);
// Account accountWithACRs = acc.Id;
for (AccountContactRelation acr : accountWithACRs.AccountContactRelations)
{
Id userId = contactToUserIdsMap.get (acr.ContactId);
if (userId != null)
{
Partner_Team_Member__c ptm = new Partner_Team_Member__c (Partner_Team_Role__c = ptr.Id,
Partner_User__c = userId,
Reason__c = 'Automatic');
ptm.put ('Account__c', o.Id);
ptmsToInsert.add (ptm);
}
}
}
}
}
insert ptmsToInsert;
}
Any help would be appreciated
public static void buildPartnerTeam (list<SObject> objects)
{
FINAL list<String> roleNames = new list<String>
{
'Account Partner',
'Account Partner Parent',
'Account Partner Manager To Self',
'Account Partner User To Self',
'Account Partner Manager',
'Account Master Agent', // jul 17
'Account- Sub Agent Super User Access Customer (Authorized)', // jul 17
'Account- Sub Agent Super User Access to Prospect or Customer (Unauthorized)', // jul 17
'Account Related Partner Contact' // MO-66
};
list<Partner_Team_Member__c> ptmsToInsert = new list<Partner_Team_Member__c>{};
map<Id,Account> partnerAccountsMap = new map<Id,Account>{};
list<Id> partnerAccountIds = new list<Id>{};
list<Partner_Team_Role__c> partnerTeamRoles = TransactionSupport.getPartnerTeamRoles (roleNames);
// list<Partner_Team_Role__c> partnerTeamRoles = [SELECT Id, Unique_Name__c FROM Partner_Team_Role__c WHERE Unique_Name__c IN :roleNames];
list<Id> accountIds = new list<Id>{};
for (SObject o : objects)
{
if (o.get('Partner_Account__c') != null) partnerAccountIds.add ((Id) o.get('Partner_Account__c'));
if (o.get('CSD_MA__c') != null) partnerAccountIds.add ((Id) o.get('CSD_MA__c'));
if (o.get('Partner_Of_Record_Cloud__c') != null) partnerAccountIds.add ((Id) o.get('Partner_Of_Record_Cloud__c'));
accountids.add (o.Id);
}
// MO-66: get AccountContactRelations
map<Id,Account> accountsWithACRsMap = new map<Id,Account>([SELECT Id,(SELECT Id, ContactId, AccountId FROM AccountContactRelations)
FROM Account WHERE Id IN :accountIds]); //This is line where I am getting this error
// system.debug('&&&'+accountsWithACRsMap);
map<Id,Id> contactToUserIdsMap = new map<Id,Id>{};
set<Id> contactIds = new set<Id>{};
// list<Account> acc = [SELECT Id,(SELECT Id, ContactId, AccountId FROM AccountContactRelations)
// FROM Account WHERE Id IN :accountIds];
// accId = accountsWithACRsMap.values();
/* for(Account acct : acc) {
system.debug('&&&'+acct);
integer count=0;
for (AccountContactRelation acr : acct.AccountContactRelations)
{
count++;
if (acr.AccountId != acct.Id) contactIds.add (acr.ContactId);
}
} */
for (Account a : accountsWithACRsMap.values())
{
for (AccountContactRelation acr : a.AccountContactRelations)
{
if (acr.AccountId != a.Id) contactIds.add (acr.ContactId);
}
}
/* for (Account a : acc)
{
for (AccountContactRelation acr : a.AccountContactRelations)
{
if (acr.AccountId != a.Id) contactIds.add (acr.ContactId);
}
} */
// MO-66: build map for Contact Id to User Id, for all AccountContactRelation records
for (User u : [SELECT Id, ContactId FROM User WHERE ContactId IN :contactIds])
{
contactToUserIdsMap.put (u.ContactId, u.Id);
}
// now add partner team members
for (Account a : [SELECT Id, Type, Partner_Account__c, ParentId, Partner_Type__c,
Sub_Agent_Authorized_to_access_cases__c
FROM Account
WHERE Id IN :partnerAccountIds])
{
partnerAccountsMap.put (a.Id, a);
}
for (SObject o : objects)
{
for (Partner_Team_Role__c ptr : partnerTeamRoles)
{
if (ptr.Unique_Name__c == roleNames[0] || // 'Account Partner'
ptr.Unique_Name__c == roleNames[4]) // 'Account Partner Manager'
{
Id lookupId = (Id) o.get ('Partner_Account__c');
if (lookupId != null)
{
Partner_Team_Member__c ptm = new Partner_Team_Member__c (Partner_Team_Role__c = ptr.Id,
Partner_Account__c = lookupId,
Reason__c = 'Automatic');
ptm.put ('Account__c', o.Id);
ptmsToInsert.add (ptm);
}
lookupId = (Id) o.get ('Partner_Of_Record_Cloud__c');
if (lookupId != null)
{
Account partnerAccount = partnerAccountsMap.get (lookupId);
if (partnerAccount.Partner_Type__c != 'Sub-Agent') // jul 17
{
Partner_Team_Member__c ptm = new Partner_Team_Member__c (Partner_Team_Role__c = ptr.Id,
Partner_Account__c = lookupId,
Reason__c = 'Automatic');
ptm.put ('Account__c', o.Id);
ptmsToInsert.add (ptm);
}
}
}
if (ptr.Unique_Name__c == roleNames[1]) // 'Account Partner Parent'
{
Account a = partnerAccountsMap.get ((Id) o.get ('Partner_Account__c'));
if (a != null)
{
if (a.Partner_Account__c != null)
{
Partner_Team_Member__c ptm = new Partner_Team_Member__c (Partner_Team_Role__c = ptr.Id,
Partner_Account__c = a.Partner_Account__c,
Reason__c = 'Automatic');
ptm.put ('Account__c', o.Id);
ptmsToInsert.add (ptm);
}
if (a.ParentId != null)
{
Partner_Team_Member__c ptm = new Partner_Team_Member__c (Partner_Team_Role__c = ptr.Id,
Partner_Account__c = a.ParentId,
Reason__c = 'Automatic');
ptm.put ('Account__c', o.Id);
ptmsToInsert.add (ptm);
}
}
Id lookupId = (Id) o.get ('ParentId');
if (lookupId != null)
{
Partner_Team_Member__c ptm = new Partner_Team_Member__c (Partner_Team_Role__c = ptr.Id,
Partner_Account__c = lookupId,
Reason__c = 'Automatic');
ptm.put ('Account__c', o.Id);
ptmsToInsert.add (ptm);
}
}
// 'Account Partner Manager To Self' or 'Account Partner User To Self'
if ((String) o.get('Type') == 'Partner' && (ptr.Unique_Name__c == roleNames[2] || ptr.Unique_Name__c == roleNames[3]))
{
Partner_Team_Member__c ptm = new Partner_Team_Member__c (Partner_Team_Role__c = ptr.Id,
Partner_Account__c = o.Id,
Reason__c = 'Automatic');
ptm.put ('Account__c', o.Id);
ptmsToInsert.add (ptm);
}
if (ptr.Unique_Name__c == roleNames[5]) // 'Account Master Agent' // Jul 17
{
Id lookupId = (Id) o.get ('CSD_MA__c');
if (lookupId != null)
{
Partner_Team_Member__c ptm = new Partner_Team_Member__c (Partner_Team_Role__c = ptr.Id,
Partner_Account__c = lookupId,
Reason__c = 'Automatic');
ptm.put ('Account__c', o.Id);
ptmsToInsert.add (ptm);
}
}
if (ptr.Unique_Name__c == roleNames[6]) // 'Account- Sub Agent Super User Access Customer (Authorized)' // Jul 17
{
Id lookupId = (Id) o.get ('Partner_Of_Record_Cloud__c');
if (lookupId != null)
{
Account partnerAccount = partnerAccountsMap.get (lookupId);
if (partnerAccount.Partner_Type__c == 'Sub-Agent' &&
partnerAccount.Sub_Agent_Authorized_to_access_cases__c == true) // jul 17
{
Partner_Team_Member__c ptm = new Partner_Team_Member__c (Partner_Team_Role__c = ptr.Id,
Partner_Account__c = lookupId,
Reason__c = 'Automatic');
ptm.put ('Account__c', o.Id);
ptmsToInsert.add (ptm);
}
}
}
if (ptr.Unique_Name__c == roleNames[7]) // 'Account- Sub Agent Super User Access to Prospect or Customer (Unauthorized)' // jul 17
{
Id lookupId = (Id) o.get ('Partner_Of_Record_Cloud__c');
if (lookupId != null)
{
Account partnerAccount = partnerAccountsMap.get (lookupId);
if (partnerAccount.Partner_Type__c == 'Sub-Agent' &&
partnerAccount.Sub_Agent_Authorized_to_access_cases__c == false) // jul 17
{
Partner_Team_Member__c ptm = new Partner_Team_Member__c (Partner_Team_Role__c = ptr.Id,
Partner_Account__c = lookupId,
Reason__c = 'Automatic');
ptm.put ('Account__c', o.Id);
ptmsToInsert.add (ptm);
}
}
}
// MO-66: Add PTMs for all Related Contacts
if (ptr.Unique_Name__c == roleNames[8]) // 'Account Related Partner Contact'
{
Account accountWithACRs = accountsWithACRsMap.get (o.Id);
// Account accountWithACRs = acc.Id;
for (AccountContactRelation acr : accountWithACRs.AccountContactRelations)
{
Id userId = contactToUserIdsMap.get (acr.ContactId);
if (userId != null)
{
Partner_Team_Member__c ptm = new Partner_Team_Member__c (Partner_Team_Role__c = ptr.Id,
Partner_User__c = userId,
Reason__c = 'Automatic');
ptm.put ('Account__c', o.Id);
ptmsToInsert.add (ptm);
}
}
}
}
}
insert ptmsToInsert;
}
Any help would be appreciated
- Aloke Singh 6
- December 03, 2019
- Like
- 0
Want to add attached document link to VF page for download or view
I have created a VF page on case to upload a file and using standard controller with extension. When user will upload a file from VF page then the attached file will be stored to a different custom object's(Custom Object is look up relationship with Case) notes and attachement. Till this everything is fine. Now my requirement is that add a attached document link to VF page so that user can download the file. I am using the below mentioned code in VF and able to see the link but it disappear when page refresh. I want to add permananetly so that user can access later as well.
<a href="/servlet/servlet.FileDownload?file={!myAttachment.id}" download="{!myAttachment.name}">{!myAttachment.name}</a>
Please help on this.
<a href="/servlet/servlet.FileDownload?file={!myAttachment.id}" download="{!myAttachment.name}">{!myAttachment.name}</a>
Please help on this.
- Aloke Singh 6
- November 06, 2019
- Like
- 0
We have three Account records like Account A is parent of account B, Account B is parent of account C.
We have three Account records like Account A is parent of account B, Account B is parent of account C. Now Account A has opportunity OP1 and OP2,Account B has opportunity OP3 and OP4,Account C has opportunity OP5 and OP6. Suppose user has updated opportunity OP3 and OP4 amount field as 500 then this should also update the Account B and Account C one custom field called 'Amount' with 500. If user has updated OP1 and OP2 with 1000 then it sholud upate the Account A with 1000 and Account B and Account C as '1500'
I want to implement this using trigger. Any help would be appreciated on this.
Thanks,
Aloke
I want to implement this using trigger. Any help would be appreciated on this.
Thanks,
Aloke
- Aloke Singh 6
- July 30, 2018
- Like
- 0
I can't able to understand why code coverage is showing only 53% for below mentioned class
I can't able to understand why code coverage is showing only 53% for below mentioned class
Class :-
public class PIREmailNotifcation {
final static string className = 'PIREmailNotifcation';
public static void MasterCaseEmail(list<case>caselist){
try{
for (case caserecord:caselist){
if( caserecord.Master_Case__c==True && caserecord.RFO_Available__c==True){
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
OrgWideEmailAddress[] owea = [select Id from OrgWideEmailAddress where Address = 'customerservicesupport-uat@mitel.com'];
system.debug('@@@@'+owea);
// string templatelabel = Label.PIRExternalEmailTemplate;
// Map<String,PIRInternalEMailIds__c> allemail = PIRInternalEMailIds__c.getAll();
//PIRInternalEMailIds__c cs = PIRInternalEMailIds__c.getAll();
String[] toAddresses = new String[] {(caserecord.ContactEmail)};
mail.setToAddresses(toAddresses);
mail.whatid=caserecord.Id;
mail.setTargetObjectId(caserecord.ContactId);
mail.setReplyTo('aloke.singh90@gmail.com');
mail.setUseSignature(false);
mail.setTemplateId('00XC0000001R6IW');
mail.saveAsActivity = True;
mail.setOrgWideEmailAddressId(owea.get(0).Id);
PIR__c[] pirid=[select Id,MasterCase_ID__c from PIR__c where MasterCase_ID__c =: caserecord.Id];
system.debug('%%%%pirid%%%'+pirid);
List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
for(Attachment a : [select Name, Body, BodyLength from Attachment where ParentId = :pirid.get(0).Id]){
Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
efa.setFileName(a.Name);
efa.setBody(a.Body);
fileAttachments.add(efa);
}
mail.setFileAttachments(fileAttachments);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
}
catch(exception me){HandlerUtility.trackException(me, className);
}
}
public static void childCaseEMail(list<case>childcase){
try{
//if(pirtriggerboolean.runOnce()){
// pirtriggerboolean.iteration= false;
set<Id> caseId = new set<Id>();
set<Id> contactId = new set<Id>();
for(case caserecord:childcase){
if(caserecord.CaseNumber != null ){
caseId.add(caserecord.Id);
}
}
//system.debug('$$$$$'+childcaseId);
Case[] childcaseId = [SELECT CaseNumber, AccountId, Id, ContactId, Subject, Description, ContactEmail, contact.name, ParentId,
SuppliedEmail FROM Case WHERE ParentId=:caseId];
system.debug('$$$$$'+childcaseId);
Map<Id,String> ContactEmail = new Map<Id, String>();
Map<Id, String> ContactFirstname = new Map<Id, String>();
for(case c:childcaseId){
contactId.add(c.ContactId);
}
list<contact> conList=[select id, email from Contact where id IN :contactId];
system.debug('$$$$$'+conList);
if(conList.size() !=null){
for(Contact c2:conList)
ContactEmail.put(c2.id,c2.email);
}
for(case childrecord :childcaseId){
for(contact cont:conList){
if(childrecord.ContactId == cont.Id ){
//string templatelabel = Label.PIRExternalEmailTemplate;
PIR__c [] pirrecordId=[select Id,MasterCase_ID__c from PIR__c where MasterCase_ID__c IN: caseId];
system.debug('$$$$$'+pirrecordId);
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
OrgWideEmailAddress[] owea = [select Id from OrgWideEmailAddress where Address = 'customerservicesupport-uat@mitel.com'];
system.debug('@@@@'+owea);
String[] toAddresses = new String[] {ContactEmail.get(cont.id)};
mail.setToAddresses(toAddresses);
mail.whatid=childrecord.Id;
mail.setTargetObjectId(childrecord.ContactId);
mail.setReplyTo('aloke.singh90@gmail.com');
mail.setUseSignature(false);
mail.setTemplateId('00X4F000000gs6W');
mail.saveAsActivity = True;
mail.setOrgWideEmailAddressId(owea.get(0).Id);
List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
for(Attachment a : [select Name, Body, BodyLength from Attachment where ParentId = :pirrecordId.get(0).Id]){
Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
efa.setFileName(a.Name);
efa.setBody(a.Body);
fileAttachments.add(efa);
}
mail.setFileAttachments(fileAttachments);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
}
// }
}
catch (exception me){HandlerUtility.trackException(me, className);
}
}
}
Test Class :-
@isTest
public class PIREmailNotifcationTest {
static{
TestDataUtility.utilityTestData();
}
static testmethod void testemailsent(){
Contact con = new Contact();
con.firstname = 'test';
con.lastname = 'test';
con.email = 'test@example.com';
insert con;
Case caserecord = TestDataUtility.CreateTestCase();
caserecord.Master_Case__c =TRUE;
caserecord.RFO_Available__c =TRUE;
caserecord.contactid = con.id;
insert caserecord;
Case ccase = TestDataUtility.createtestcase();
ccase.parentid = caserecord.id;
ccase.contactid = con.id;
PIR__c pirrecord = new PIR__c();
pirrecord.Name = '12345';
pirrecord.CurrencyIsoCode='USD';
pirrecord.MasterCase_ID__c=caserecord.Id;
insert pirrecord;
Attachment myAttachment = new Attachment();
myAttachment.Body= Blob.valueOf('Test Attachment Body');
myAttachment.ParentId= pirrecord.Id;
myAttachment.Name='ABC';
insert myAttachment;
system.debug ('BodyLength::'+ myattachment.BodyLength);
caserecord.Master_Case__c =TRUE;
caserecord.RFO_Available__c =TRUE;
update caserecord;
/* List<Attachment> att = [Select id from attachment where parentid =: pirrecord.id];
System.assertEquals(1, att.size());
EmailMessage outGoingMail= new EmailMessage();
outGoingMail.fromaddress='test@test.com';
outGoingMail.toAddress = 'con1.Email';
outGoingMail.subject = 'Opt Out Test Message';
outGoingMail.TextBody= 'This is the message body BR-Interno.';
outGOingMail.ParentID = caserecord.id;
insert outGoingMail; */
}
}
Class :-
public class PIREmailNotifcation {
final static string className = 'PIREmailNotifcation';
public static void MasterCaseEmail(list<case>caselist){
try{
for (case caserecord:caselist){
if( caserecord.Master_Case__c==True && caserecord.RFO_Available__c==True){
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
OrgWideEmailAddress[] owea = [select Id from OrgWideEmailAddress where Address = 'customerservicesupport-uat@mitel.com'];
system.debug('@@@@'+owea);
// string templatelabel = Label.PIRExternalEmailTemplate;
// Map<String,PIRInternalEMailIds__c> allemail = PIRInternalEMailIds__c.getAll();
//PIRInternalEMailIds__c cs = PIRInternalEMailIds__c.getAll();
String[] toAddresses = new String[] {(caserecord.ContactEmail)};
mail.setToAddresses(toAddresses);
mail.whatid=caserecord.Id;
mail.setTargetObjectId(caserecord.ContactId);
mail.setReplyTo('aloke.singh90@gmail.com');
mail.setUseSignature(false);
mail.setTemplateId('00XC0000001R6IW');
mail.saveAsActivity = True;
mail.setOrgWideEmailAddressId(owea.get(0).Id);
PIR__c[] pirid=[select Id,MasterCase_ID__c from PIR__c where MasterCase_ID__c =: caserecord.Id];
system.debug('%%%%pirid%%%'+pirid);
List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
for(Attachment a : [select Name, Body, BodyLength from Attachment where ParentId = :pirid.get(0).Id]){
Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
efa.setFileName(a.Name);
efa.setBody(a.Body);
fileAttachments.add(efa);
}
mail.setFileAttachments(fileAttachments);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
}
catch(exception me){HandlerUtility.trackException(me, className);
}
}
public static void childCaseEMail(list<case>childcase){
try{
//if(pirtriggerboolean.runOnce()){
// pirtriggerboolean.iteration= false;
set<Id> caseId = new set<Id>();
set<Id> contactId = new set<Id>();
for(case caserecord:childcase){
if(caserecord.CaseNumber != null ){
caseId.add(caserecord.Id);
}
}
//system.debug('$$$$$'+childcaseId);
Case[] childcaseId = [SELECT CaseNumber, AccountId, Id, ContactId, Subject, Description, ContactEmail, contact.name, ParentId,
SuppliedEmail FROM Case WHERE ParentId=:caseId];
system.debug('$$$$$'+childcaseId);
Map<Id,String> ContactEmail = new Map<Id, String>();
Map<Id, String> ContactFirstname = new Map<Id, String>();
for(case c:childcaseId){
contactId.add(c.ContactId);
}
list<contact> conList=[select id, email from Contact where id IN :contactId];
system.debug('$$$$$'+conList);
if(conList.size() !=null){
for(Contact c2:conList)
ContactEmail.put(c2.id,c2.email);
}
for(case childrecord :childcaseId){
for(contact cont:conList){
if(childrecord.ContactId == cont.Id ){
//string templatelabel = Label.PIRExternalEmailTemplate;
PIR__c [] pirrecordId=[select Id,MasterCase_ID__c from PIR__c where MasterCase_ID__c IN: caseId];
system.debug('$$$$$'+pirrecordId);
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
OrgWideEmailAddress[] owea = [select Id from OrgWideEmailAddress where Address = 'customerservicesupport-uat@mitel.com'];
system.debug('@@@@'+owea);
String[] toAddresses = new String[] {ContactEmail.get(cont.id)};
mail.setToAddresses(toAddresses);
mail.whatid=childrecord.Id;
mail.setTargetObjectId(childrecord.ContactId);
mail.setReplyTo('aloke.singh90@gmail.com');
mail.setUseSignature(false);
mail.setTemplateId('00X4F000000gs6W');
mail.saveAsActivity = True;
mail.setOrgWideEmailAddressId(owea.get(0).Id);
List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
for(Attachment a : [select Name, Body, BodyLength from Attachment where ParentId = :pirrecordId.get(0).Id]){
Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
efa.setFileName(a.Name);
efa.setBody(a.Body);
fileAttachments.add(efa);
}
mail.setFileAttachments(fileAttachments);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
}
// }
}
catch (exception me){HandlerUtility.trackException(me, className);
}
}
}
Test Class :-
@isTest
public class PIREmailNotifcationTest {
static{
TestDataUtility.utilityTestData();
}
static testmethod void testemailsent(){
Contact con = new Contact();
con.firstname = 'test';
con.lastname = 'test';
con.email = 'test@example.com';
insert con;
Case caserecord = TestDataUtility.CreateTestCase();
caserecord.Master_Case__c =TRUE;
caserecord.RFO_Available__c =TRUE;
caserecord.contactid = con.id;
insert caserecord;
Case ccase = TestDataUtility.createtestcase();
ccase.parentid = caserecord.id;
ccase.contactid = con.id;
PIR__c pirrecord = new PIR__c();
pirrecord.Name = '12345';
pirrecord.CurrencyIsoCode='USD';
pirrecord.MasterCase_ID__c=caserecord.Id;
insert pirrecord;
Attachment myAttachment = new Attachment();
myAttachment.Body= Blob.valueOf('Test Attachment Body');
myAttachment.ParentId= pirrecord.Id;
myAttachment.Name='ABC';
insert myAttachment;
system.debug ('BodyLength::'+ myattachment.BodyLength);
caserecord.Master_Case__c =TRUE;
caserecord.RFO_Available__c =TRUE;
update caserecord;
/* List<Attachment> att = [Select id from attachment where parentid =: pirrecord.id];
System.assertEquals(1, att.size());
EmailMessage outGoingMail= new EmailMessage();
outGoingMail.fromaddress='test@test.com';
outGoingMail.toAddress = 'con1.Email';
outGoingMail.subject = 'Opt Out Test Message';
outGoingMail.TextBody= 'This is the message body BR-Interno.';
outGOingMail.ParentID = caserecord.id;
insert outGoingMail; */
}
}
- Aloke Singh 6
- January 09, 2020
- Like
- 0