• Chinmay Abhangrao
  • NEWBIE
  • 20 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 6
    Replies
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ProdTrackOnAcc: execution of AfterInsert  caused by: System.ListException: Duplicate id in list: 0016F00002OuVyiQAF  Class.trigger_helper.trigger_method_when_inserted: line 54, column 1 Trigger.ProdTrackOnAcc: line 10, column 1: []
ABC Firm needs to see total expenditure on running campaigns against each Account in their Organization. This would be one of the key parameters to measure investment vs returns.
Requirement Details:-
Create a custom number field on Account and name it ‘Total Campaign Cost’
Create a lookup relationship on Campaign as Account.
Use Campaign ‘Actual Cost’ field for operations.
Each time a campaign status is marked as ‘Completed’ add the amount into ‘Total Campaign Cost’ field of account.
Update Account Status:
If Total Campaign Cost on Account is greater than $10,000 : Platinum
If Total Campaign Cost on Account is > $8,000 & <$10,000 : Gold
If Total Campaign Cost on Account is <$8,000: Silver
The code should be able to handle bulk data; meaning multiple campaigns can be added/updated with status as ‘Completed’ using Import Wizard or Data
loader
Code should adhere to programming best practices like
Standardized Naming conventions
Apt utilization of collection elements
Follow of Trigger pattern
Avoiding Trigger recurrence on same object
Proper Code comments
Keeping Salesforce Governor limits into consideration
Create test class to ensure developed code can be deployed; adhere to best practices of testing framework

 
I have written this test class but it fails all the time and when I commit the system.assert();statement then it works fine.Anybody can explain where I am lagging? 

@istest public class TestingExam {
    @istest public static void Testing(){
        
        Account ac=new account();
        ac.Name='chinamyab';
        insert ac;
        
        case c=new case();
        c.AccountId=ac.Id;
        c.Status='working';
        c.Origin='phone';
        c.Product__c='GC1040';
        insert c;
        System.assertEquals(1,ac.Total_Issue_Count__c);
        System.assertEquals('GC1040',ac.Current_Issue__c);

    }

}
I have written this trigger :-

    CustmSettOnTrig_Camp__c obj=CustmSettOnTrig_Camp__c.getInstance();
    
     if(obj.isActive__c==true ){                         //Bold lines denote the custom setting provided by me and i want this line should be tested in the                                                                                     test class
        
         Set<id> accId =new Set<id>();
         list<Account> listAccToUp =new list<Account>();
        if(Trigger.isInsert ||Trigger.isUpdate){
//some code.. }

And i have written test class for that is :-



@istest public class TestClass_ForTrig_OnCamp {
    @istest public static void createCampaign(){
             
        CustmSettOnTrig_Camp__c obj=CustmSettOnTrig_Camp__c.getInstance();
        obj.isActive__c=true; //Something wrong here if i commit the custom setting in trigger the code coverage is 70% and if i didnt commit that                                                          code then the code covergae is 8%
      //some code  
      

 
 If(Trigger.isinsert && Trigger.isafter){
    set<id> setid=new set<id>();
    for(Case c:trigger.new )
    {
       setid.add(c.AccountId);    
    } 
    list<account> acctoup=new list<account>();
    map<id,Account> acclist=new map<id,Account>([select id,Current_Issue__c,Past_Issue__c,Total_Issue_Count__c from account where id=:setid]);
 
        for(Case c:trigger.new)
        {
        account a=acclist.get(c.AccountId);
            account a=acclist.get(c.AccountId);
           String EmailIdOfOwner =[SELECT Account.Owner.Email FROM Case WHERE c.id =a.Id]; // Something Wrong here  
        }
 
ABC Firm needs to see total expenditure on running campaigns against each Account in their Organization. This would be one of the key parameters to measure investment vs returns.
Requirement Details:-
Create a custom number field on Account and name it ‘Total Campaign Cost’
Create a lookup relationship on Campaign as Account.
Use Campaign ‘Actual Cost’ field for operations.
Each time a campaign status is marked as ‘Completed’ add the amount into ‘Total Campaign Cost’ field of account.
Update Account Status:
If Total Campaign Cost on Account is greater than $10,000 : Platinum
If Total Campaign Cost on Account is > $8,000 & <$10,000 : Gold
If Total Campaign Cost on Account is <$8,000: Silver
The code should be able to handle bulk data; meaning multiple campaigns can be added/updated with status as ‘Completed’ using Import Wizard or Data
loader
Code should adhere to programming best practices like
Standardized Naming conventions
Apt utilization of collection elements
Follow of Trigger pattern
Avoiding Trigger recurrence on same object
Proper Code comments
Keeping Salesforce Governor limits into consideration
Create test class to ensure developed code can be deployed; adhere to best practices of testing framework

 
I have written this test class but it fails all the time and when I commit the system.assert();statement then it works fine.Anybody can explain where I am lagging? 

@istest public class TestingExam {
    @istest public static void Testing(){
        
        Account ac=new account();
        ac.Name='chinamyab';
        insert ac;
        
        case c=new case();
        c.AccountId=ac.Id;
        c.Status='working';
        c.Origin='phone';
        c.Product__c='GC1040';
        insert c;
        System.assertEquals(1,ac.Total_Issue_Count__c);
        System.assertEquals('GC1040',ac.Current_Issue__c);

    }

}
 If(Trigger.isinsert && Trigger.isafter){
    set<id> setid=new set<id>();
    for(Case c:trigger.new )
    {
       setid.add(c.AccountId);    
    } 
    list<account> acctoup=new list<account>();
    map<id,Account> acclist=new map<id,Account>([select id,Current_Issue__c,Past_Issue__c,Total_Issue_Count__c from account where id=:setid]);
 
        for(Case c:trigger.new)
        {
        account a=acclist.get(c.AccountId);
            account a=acclist.get(c.AccountId);
           String EmailIdOfOwner =[SELECT Account.Owner.Email FROM Case WHERE c.id =a.Id]; // Something Wrong here  
        }