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

Need help for code coverage!! urgent...
public class LeadCovertclass { @AuraEnabled Public lead lObj; @AuraEnabled Public Id leadId; @AuraEnabled Public Id oppId, accountId, contactId ; @AuraEnabled public Boolean showOpportunity { get; set; } @AuraEnabled public boolean isVisible {get;set;} @AuraEnabled public String Accountfounds {get; set;} @AuraEnabled public String oppName {get; set;} @AuraEnabled public String accountName {get; set;} @AuraEnabled public String contactName {get; set;} private Account [] findCompany (string companyName) { //perform the SOSL query List<List<SObject>> searchList = [ FIND :companyName IN NAME FIELDS RETURNING Account( Id, Name ) ]; List <Account> accountsFound = new List<Account>(); for (List <sobject> sObjs : searchList) { for (sObject s : sObjs) { //add the account that was found to the list of found accounts accountsFound.add((Account) s); } } // return the list of found accounts return accountsFound; } @AuraEnabled public static LeadCovertclass autoConvertRun(Id leadid) { LeadCovertclass obj = new LeadCovertclass(); obj.isVisible = false; Lead l = [Select Id, Name, isConverted, Company From Lead where id= :leadid limit 1]; if(l.isConverted == false){ obj.isVisible = true; string company = l.Company; Account [] accountsFound = obj.findCompany(company + '*'); Database.LeadConvert lc = new database.LeadConvert(); lc.setLeadId(leadId); if (accountsFound != null && accountsFound.size() > 0) { for (Account a : accountsFound) { lc.setAccountId(a.Id); AggregateResult[] oppcount = [SELECT COUNT(Id), AccountId FROM Opportunity where AccountId=:a.Id GROUP BY AccountId]; if(oppcount.size() > 0){ lc.setDoNotCreateOpportunity(true); obj.showOpportunity = false; } } } LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1]; lc.setConvertedStatus(convertStatus.MasterLabel); Database.LeadConvertResult lcr = Database.convertLead(lc); System.assert(lcr.isSuccess()); if (lcr.isSuccess()) { obj.oppId = lcr.getOpportunityId(); if(obj.oppId != null){ obj.showOpportunity = true; Opportunity opp = [SELECT Name from Opportunity where id =: obj.oppId]; obj.oppName = opp.Name; } obj.accountId = lcr.getAccountId(); obj.contactId = lcr.getContactId(); Account acc = [SELECT Name from Account where id =: obj.accountId]; obj.accountName = acc.Name; Contact cn = [SELECT Name from Contact where id =: obj.contactId]; obj.contactName = cn.Name; } return obj; } else return null; } }
All Answers
only these line are not covering....
if (accountsFound != null && accountsFound.size() > 0) {
for (Account a : accountsFound) {
lc.setAccountId(a.Id);
AggregateResult[] oppcount = [SELECT COUNT(Id), AccountId FROM Opportunity where AccountId=:a.Id GROUP BY AccountId];
if(oppcount.size() > 0){
lc.setDoNotCreateOpportunity(true);
obj.showOpportunity = false;
}
}
}