• DazedPuzzled
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 5
    Replies
Hello,

I have a trigger and test class below.  I am only getting 7% coverage on my trigger and I don't understand why.  Can anyone help?

Trigger:
trigger UpdateConsultOpp on Opportunity (before insert, before update) {   

if(checkRecursiveBI.runOnceBI()||checkRecursiveBU.runOnceBU())
{
   
    Set<ID> setOppIds = new Set<ID>();
/*    List<Opportunity> opp1 = [SELECT Id
                             FROM Opportunity
                             WHERE Id IN: Trigger.newMap.keySet()]; 
                                     
    for (Opportunity opp :opp1){*/
    for(Opportunity opp:Trigger.new){
        setOppIds.add(opp.Id);
    }
    Map<ID, Opportunity> mapAcc = new Map<ID, Opportunity>([Select Id, Account.Consultant_Partner_Primary__c, Account.Consultant_Partner_Secondary__c, Consultant_Type__c
                                                            FROM Opportunity
                                                            WHERE Id in:setOppIds]);
    if(mapAcc.size()>0){
    List<Opportunity> opp2 = [SELECT Id,Consultant_Type__c,Consultant_Partner__c
                             FROM Opportunity
                             WHERE Id IN: Trigger.new]; 
                                     
        for (Opportunity opp :opp2){
//        for(Opportunity opp:Trigger.New){
            IF(mapAcc.containsKey(opp.Id) && opp.Consultant_Type__c == 'Primary Consultant'){
                opp.Consultant_Partner__c = mapAcc.get(opp.Id).Account.Consultant_Partner_Primary__c;
            }
            ELSE IF(mapAcc.containsKey(opp.Id) && opp.Consultant_Type__c == 'Secondary Consultant'){
                opp.Consultant_Partner__c = mapAcc.get(opp.Id).Account.Consultant_Partner_Secondary__c;
            }
        }
    }
}

}

Test Class:
@isTest private class TestOppConsultants {

    @isTest private static void testOppConsults() {
       
    Account acct1 = TestAcctTeamCreate.createAcct(0);
    insert acct1;
        
    Account acct2 = TestConsultAcctCreate.createConsult1(0);
    insert acct2;
  
    Account acct3 = TestConsultAcctCreate.createConsult2(0);
    insert acct3;
  
    Opportunity opp1 = TestOppCreate3.createOpp(acct1.Id);
    insert opp1;

        Account acctPrim = [SELECT Id, Consultant_Partner_Primary__c
                            FROM Account
                            WHERE Id =: acct1.Id];
            acctPrim.Consultant_Partner_Primary__c = acct2.Id;
        update acctPrim;

        
        Opportunity oppPrim = [SELECT Id, Consultant_Type__c
                                FROM Opportunity
                                WHERE Id =: opp1.Id];
            oppPrim.Consultant_Type__c = 'Primary Consultant';
        update oppPrim;
            

        Account acctPrim1 = [SELECT Id, Consultant_Partner_Primary__c
                            FROM Account
                            WHERE Id =: acct1.Id];
            acctPrim1.Consultant_Partner_Primary__c = acct3.Id;
        update acctPrim1;


        Account acctSec = [SELECT Id, Consultant_Partner_Secondary__c
                           FROM Account
                           WHERE Id =: acct1.Id];
            acctSec.Consultant_Partner_Secondary__c = acct3.Id;
        update acctSec;

        
        Opportunity oppSec = [SELECT Id, Consultant_Type__c
                                FROM Opportunity
                                WHERE Id =: opp1.Id];
            oppSec.Consultant_Type__c = 'Secondary Consultant';
        update oppSec;


        Account acctSec1 = [SELECT Id, Consultant_Partner_Secondary__c
                           FROM Account
                           WHERE Id =: acct1.Id];
            acctSec1.Consultant_Partner_Secondary__c = acct2.Id;
        update acctSec1;

        
    Test.startTest();
        update acct1;
        update acct2;
        update acct3;
        update opp1;
        update acctPrim;
        update oppPrim;
        update acctPrim1;
        update acctSec;    
        update oppSec;    
        update acctSec1;    
    Test.stopTest();
    }
}



  • July 02, 2014
  • Like
  • 0
I've created the following trigger and it is only updating the task before an update and not before an insert. Help me troubleshoot?

trigger EmailISResponse on Task (before insert, before update) {

List<User> InsideSalesUser = [SELECT Id FROM User where UserRoleId='00E30000001rctV'];

Set<Id> InsideSalesUserId = new set<Id>();
if (InsideSalesUser != NULL){

for (User u :InsideSalesUser) {
    InsideSalesUserId.add(u.Id);
    }
}

List<Lead> LeadsWithCampaign = [SELECT Id FROM Lead where Current_Teleprospecting_Campaign__c != NULL];
Set<Id> LeadsWithCampaignId = new set<Id>();
if (LeadsWithCampaign != NULL){

for (Lead l :LeadsWithCampaign) {
    LeadsWithCampaignId.add(l.id);
    }
}

for (Task t: Trigger.new) {
    if(InsideSalesUserId.contains(t.OwnerID) && t.WhoId != NULL && LeadsWithCampaignId.contains(t.WhoId) && t.IsClosed == true && String.valueOf(t.WhoId).startsWith('00Q')&& t.Subject != NULL && String.valueOf(t.Subject).startsWith('Email'))
    
    t.IS_Response__c = true;
    }
}


Hi,

I need Picklist values in BusinessProcess for Lead in Apex.
Can anybody please tell me the approach to get those values in APEX.
I required values while converting the lead to assign the lead status status.

I would be greatefull if anybody shows the approach.

Thanks.