You need to sign in to do that
Don't have an account?
Krishna Sahu 1
Need help to write test class on the classs
public static void leadConversion(List<flowInputs> leadIdSet){
System.debug('This is the lead Id from Convert Lead Flow===>'+leadIdSet[0]);
Map<Id, Case> mapCases = new Map<Id, Case>();
List<CaseTeamMember> listCaseTeamMember = new List<CaseTeamMember>();
List<Database.LeadConvert> leadsToConvert = new List<Database.LeadConvert>();
for(Id leadId: leadIdSet[0].ids){
Database.LeadConvert newConvertLead = new Database.LeadConvert();
newConvertLead.setLeadId(leadId);
newConvertLead.setDoNotCreateOpportunity(true);
newConvertLead.setConvertedStatus(leadConvertedStatus);
leadsToConvert.add(newConvertLead);
}
if(!leadsToConvert.isEmpty())
{
List<Database.LeadConvertResult> convertResult = Database.convertLead(leadsToConvert);
CaseTeamRole caseTeamRole = [SELECT Id,Name FROM CaseTeamRole WHERE Name ='Care Coordinator' LIMIT 1];
Set<Id> setAccountIds = new Set<Id>();
Map<Id, Id> mapAccountIdToContactId = new Map<Id, Id>();
for(Database.LeadConvertResult convertedLead : convertResult)
{
mapAccountIdToContactId.put(convertedLead.getAccountId(), convertedLead.getContactId());
}
Map<Id, Account> mapAccounts = new Map<Id, Account>([SELECT Id, OwnerId,
sales_representative__c, Name
FROM Account
WHERE Id IN :mapAccountIdToContactId.keyset() AND sales_representative__c !=null]);
if(!mapAccounts.isEmpty())
{
for(Account accountRecord : mapAccounts.values())
{
if(accountRecord.OwnerId != null && accountRecord.Name !=null)
{
mapCases.put(accountRecord.Id, new Case(OwnerId = accountRecord.OwnerId,
ContactId = mapAccountIdToContactId.get(accountRecord.Id),
AccountId = accountRecord.Id,
Status = 'New',
Subject = accountRecord.Name+' Care Plan'));
}
}
insert mapCases.values();
List<CaseTeamMember> lstCareTeamMembers = new List<CaseTeamMember>();
for(Case objCase : mapCases.values())
{
lstCareTeamMembers.add(new CaseTeamMember(ParentId = objCase.Id,
MemberId = mapAccounts.get(objCase.AccountId).sales_representative__c,
TeamRoleId = caseTeamRole.Id));
}
insert lstCareTeamMembers;
}
}
System.debug('This is the lead Id from Convert Lead Flow===>'+leadIdSet[0]);
Map<Id, Case> mapCases = new Map<Id, Case>();
List<CaseTeamMember> listCaseTeamMember = new List<CaseTeamMember>();
List<Database.LeadConvert> leadsToConvert = new List<Database.LeadConvert>();
for(Id leadId: leadIdSet[0].ids){
Database.LeadConvert newConvertLead = new Database.LeadConvert();
newConvertLead.setLeadId(leadId);
newConvertLead.setDoNotCreateOpportunity(true);
newConvertLead.setConvertedStatus(leadConvertedStatus);
leadsToConvert.add(newConvertLead);
}
if(!leadsToConvert.isEmpty())
{
List<Database.LeadConvertResult> convertResult = Database.convertLead(leadsToConvert);
CaseTeamRole caseTeamRole = [SELECT Id,Name FROM CaseTeamRole WHERE Name ='Care Coordinator' LIMIT 1];
Set<Id> setAccountIds = new Set<Id>();
Map<Id, Id> mapAccountIdToContactId = new Map<Id, Id>();
for(Database.LeadConvertResult convertedLead : convertResult)
{
mapAccountIdToContactId.put(convertedLead.getAccountId(), convertedLead.getContactId());
}
Map<Id, Account> mapAccounts = new Map<Id, Account>([SELECT Id, OwnerId,
sales_representative__c, Name
FROM Account
WHERE Id IN :mapAccountIdToContactId.keyset() AND sales_representative__c !=null]);
if(!mapAccounts.isEmpty())
{
for(Account accountRecord : mapAccounts.values())
{
if(accountRecord.OwnerId != null && accountRecord.Name !=null)
{
mapCases.put(accountRecord.Id, new Case(OwnerId = accountRecord.OwnerId,
ContactId = mapAccountIdToContactId.get(accountRecord.Id),
AccountId = accountRecord.Id,
Status = 'New',
Subject = accountRecord.Name+' Care Plan'));
}
}
insert mapCases.values();
List<CaseTeamMember> lstCareTeamMembers = new List<CaseTeamMember>();
for(Case objCase : mapCases.values())
{
lstCareTeamMembers.add(new CaseTeamMember(ParentId = objCase.Id,
MemberId = mapAccounts.get(objCase.AccountId).sales_representative__c,
TeamRoleId = caseTeamRole.Id));
}
insert lstCareTeamMembers;
}
}
Can you share the full class code.??
Thanks!!
This is the full code.
public static void leadConversion(List<flowInputs> leadIdSet){
System.debug('This is the lead Id from Convert Lead Flow===>'+leadIdSet[0]);
Map<Id, Case> mapCases = new Map<Id, Case>();
List<CaseTeamMember> listCaseTeamMember = new List<CaseTeamMember>();
List<Database.LeadConvert> leadsToConvert = new List<Database.LeadConvert>();
for(Id leadId: leadIdSet[0].ids){
Database.LeadConvert newConvertLead = new Database.LeadConvert();
newConvertLead.setLeadId(leadId);
newConvertLead.setDoNotCreateOpportunity(true);
newConvertLead.setConvertedStatus(leadConvertedStatus);
leadsToConvert.add(newConvertLead);
}
if(!leadsToConvert.isEmpty())
{
List<Database.LeadConvertResult> convertResult = Database.convertLead(leadsToConvert);
CaseTeamRole caseTeamRole = [SELECT Id,Name FROM CaseTeamRole WHERE Name ='Care Coordinator' LIMIT 1];
Set<Id> setAccountIds = new Set<Id>();
Map<Id, Id> mapAccountIdToContactId = new Map<Id, Id>();
for(Database.LeadConvertResult convertedLead : convertResult)
{
mapAccountIdToContactId.put(convertedLead.getAccountId(), convertedLead.getContactId());
}
Map<Id, Account> mapAccounts = new Map<Id, Account>([SELECT Id, OwnerId,
sales_representative__c, Name
FROM Account
WHERE Id IN :mapAccountIdToContactId.keyset() AND sales_representative__c !=null]);
if(!mapAccounts.isEmpty())
{
for(Account accountRecord : mapAccounts.values())
{
if(accountRecord.OwnerId != null && accountRecord.Name !=null)
{
mapCases.put(accountRecord.Id, new Case(OwnerId = accountRecord.OwnerId,
ContactId = mapAccountIdToContactId.get(accountRecord.Id),
AccountId = accountRecord.Id,
Status = 'New',
Subject = accountRecord.Name+' Care Plan'));
}
}
insert mapCases.values();
List<CaseTeamMember> lstCareTeamMembers = new List<CaseTeamMember>();
for(Case objCase : mapCases.values())
{
lstCareTeamMembers.add(new CaseTeamMember(ParentId = objCase.Id,
MemberId = mapAccounts.get(objCase.AccountId).sales_representative__c,
TeamRoleId = caseTeamRole.Id));
}
insert lstCareTeamMembers;
}
}
}
public class flowInputs {
@InvocableVariable
public List<Id> ids;
}
try with below code as an example and try.
If this helps, Please mark it as best answer.
Thanks!!
Your codes is not working
You need to insert the proper data in the test class .
Thanks!!