• Joe Rodden 7
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 3
    Replies
Hi, 

The class below is supposed to fire an error message if the Total of Sales Invoices goes over the opportunity Amount of the opp they're associated to. For some reason it's just doing nothing and I've been wracking my brain to figure out why. I'm fairly new to development so I'm sure it's something basic. 

Trigger:
trigger MasterSalesInvoiceTrigger on Sales_Invoice__c (
  before insert, after insert, 
  before update, after update, 
  before delete, after delete,
  after undelete) {

  if (Trigger.isBefore) {
    if (Trigger.isInsert) {

        SalesInvoice_InvoiceTotalValidation.siTotalValidation(Trigger.new, Trigger.oldMap);
    } 
    if (Trigger.isUpdate) {
		SalesInvoice_InvoiceTotalValidation.siTotalValidation(Trigger.new, Trigger.oldMap);

            }
    if (Trigger.isDelete) {

    }
  }

  if (Trigger.IsAfter) {
    if (Trigger.isInsert) {

    } 
    if (Trigger.isUpdate) {

    }
    if (Trigger.isDelete) {

    }
    if (Trigger.isUndelete){

      }
  }
}



Class:
public class SalesInvoice_InvoiceTotalValidation {

    public static void siTotalValidation(List<Sales_Invoice__c> trigSi, Map<Id, Sales_Invoice__c> oldSIMap) {
        Map<Id, Decimal> siTotal   							= new Map<Id, Decimal>(); //Holds the sum of all inserted and updated sales invoices
        Map<Id, Decimal> oppAmount 							= new Map<Id, Decimal>(); //Hold the current amount for the opportunity
        Map<Id, List<Sales_Invoice__c>> oppIdToSalesInvoice = new Map<Id, List<Sales_Invoice__c>>(); //Maps the opp Id to the Sales Invoices for the error message
        Set<Id> oppIdSet		  						    = new Set<Id>(); //Used to create the key for siTotal and oppAmount when calling error
        
        //Filling up maps
        for (Sales_Invoice__c si : trigSi) {
            if (siTotal.containsKey(si.Opportunity__c)) {
                siTotal.put(si.Opportunity__c, si.Total__c + siTotal.get(si.Opportunity__c));
            } else {
                siTotal.put(si.Opportunity__c, si.Total__c);
            } 
            
            if(oppIdToSalesInvoice.containsKey(si.Opportunity__c)) {
                oppIdToSalesInvoice.get(si.Opportunity__c).add(si);
            } else {
                oppIdToSalesInvoice.put(si.Opportunity__c, new List<Sales_Invoice__c>{si});
            }
            
            oppAmount.put(si.Opportunity__c, si.Opportunity__r.Amount);
		}

	      
        oppIdSet = siTotal.keySet();
        for(Id oppId  : oppIdSet) {
            if(siTotal.get(oppId) > oppAmount.get(oppId)){
                for(Sales_Invoice__c si2 : oppIdToSalesInvoice.get(oppId)) {
                    si2.addError('Total of all Sales Invoices cant be greater than opportunity amount. Adjust opp amount first then adjust the Sales Invoices.');
                }
            }
        }
        
        
        
    }
}

 
Fairly new so bear with me. I've written a class that throws an error message for any duplicate emails on Contacts. While writing the test I thought I'd covered everything the original class does however I'm only ending up with 85% code coverage. I'd like to figure out how to get to 100. 

Class (the lines that aren't covered are bolded and underlined):
 
public class Contact_CheckEmail {

    List<Contact> contacts = new List<Contact>();
    
    public Contact_CheckEmail(List<Contact> trigCon){
       contacts = trigCon; 
    }
    

    public void checkEmail(){
    Set<String> emailSet = new Set<String>();
    
    for(Contact c : contacts){
        
        emailSet.add(c.Email);
    
    }
    
    List<Contact> duplicateEmail = [SELECT Email FROM Contact WHERE Email IN: emailSet];
    
    Set<String> duplicateEmailId = new Set<String>();
    
    for(Contact c : duplicateEmail) {
    
        duplicateEmailId.add(c.Email);
    
    }

    for(Contact c: contacts){
        if(duplicateEmailId.contains(c.Email)){
               c.addError('Email already exists.');
        
        }
    
    }
    
}
}


Test Class:
@isTest
public class Test_CheckEmail {
    
    @isTest static void EmailCheckTest(){
        
        Account acc = new Account();
        acc.Name = 'TestAccount';
        insert acc;
        
        List<Contact> contacts = new List<Contact>();
        for( Integer i = 0;i < 1; i++){
            String iString = String.valueof(i);
            Contact myCon = new Contact();
            myCon.LastName = 'iString';
            myCon.AccountId = acc.Id;
            myCon.Email = 'fakeman@fake.com';
            contacts.add(myCon);
        }
        
        try{
        insert contacts;
        }
        catch (Exception e){
            Boolean expectedException = e.getMessage().contains('Email already exists.') ? true : false;
            System.assertEquals(expectedException, true);
        }
        
        List<Contact> contacts2 = new List<Contact>();
        for( Integer i = 0;i < 1; i++){
            String iString = String.valueof(i);
            Contact myCon = new Contact();
            myCon.LastName = 'iString';
            myCon.AccountId = acc.Id;
            myCon.Email = iString + '@fake.com';
            contacts2.add(myCon);
        }
        
        try{
        insert contacts2;
        }
        catch (Exception e){
            Boolean expectedException = e.getMessage().contains('Email already exists.') ? true : false;
            System.assertEquals(expectedException, false);
        }
        
        
        
    }

}

 
Running into the following error via the Debug Console when running a flow:
System.QueryException: Non-selective query against large object type (more than 200000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times)

The flow essentially takes a unique identifier on a custom object and attempts to find a lead or contact with that same unique ID. Worked fine in a sandbox, but when pushing into our full copy it no longer works if it has to look for a lead. My guess is it's because there are so many leads. Any thoughts on how to get around this limit via flow? Not a developer by trade. Current flow below, its called via process builder when the custom object is inserted.

User-added image
I am updating a lead via API using a python script. Lead assignment rule fire and reassign lead eveytime the script updates the lead record. Any idea why this is happening? It is only if this particular integration updates a lead that they re-fire. We have no functionality causing them to fire upon edit and there is nothing in the integration that is specifically saying they should fire.
Fairly new so bear with me. I've written a class that throws an error message for any duplicate emails on Contacts. While writing the test I thought I'd covered everything the original class does however I'm only ending up with 85% code coverage. I'd like to figure out how to get to 100. 

Class (the lines that aren't covered are bolded and underlined):
 
public class Contact_CheckEmail {

    List<Contact> contacts = new List<Contact>();
    
    public Contact_CheckEmail(List<Contact> trigCon){
       contacts = trigCon; 
    }
    

    public void checkEmail(){
    Set<String> emailSet = new Set<String>();
    
    for(Contact c : contacts){
        
        emailSet.add(c.Email);
    
    }
    
    List<Contact> duplicateEmail = [SELECT Email FROM Contact WHERE Email IN: emailSet];
    
    Set<String> duplicateEmailId = new Set<String>();
    
    for(Contact c : duplicateEmail) {
    
        duplicateEmailId.add(c.Email);
    
    }

    for(Contact c: contacts){
        if(duplicateEmailId.contains(c.Email)){
               c.addError('Email already exists.');
        
        }
    
    }
    
}
}


Test Class:
@isTest
public class Test_CheckEmail {
    
    @isTest static void EmailCheckTest(){
        
        Account acc = new Account();
        acc.Name = 'TestAccount';
        insert acc;
        
        List<Contact> contacts = new List<Contact>();
        for( Integer i = 0;i < 1; i++){
            String iString = String.valueof(i);
            Contact myCon = new Contact();
            myCon.LastName = 'iString';
            myCon.AccountId = acc.Id;
            myCon.Email = 'fakeman@fake.com';
            contacts.add(myCon);
        }
        
        try{
        insert contacts;
        }
        catch (Exception e){
            Boolean expectedException = e.getMessage().contains('Email already exists.') ? true : false;
            System.assertEquals(expectedException, true);
        }
        
        List<Contact> contacts2 = new List<Contact>();
        for( Integer i = 0;i < 1; i++){
            String iString = String.valueof(i);
            Contact myCon = new Contact();
            myCon.LastName = 'iString';
            myCon.AccountId = acc.Id;
            myCon.Email = iString + '@fake.com';
            contacts2.add(myCon);
        }
        
        try{
        insert contacts2;
        }
        catch (Exception e){
            Boolean expectedException = e.getMessage().contains('Email already exists.') ? true : false;
            System.assertEquals(expectedException, false);
        }
        
        
        
    }

}

 
Hi, 

The class below is supposed to fire an error message if the Total of Sales Invoices goes over the opportunity Amount of the opp they're associated to. For some reason it's just doing nothing and I've been wracking my brain to figure out why. I'm fairly new to development so I'm sure it's something basic. 

Trigger:
trigger MasterSalesInvoiceTrigger on Sales_Invoice__c (
  before insert, after insert, 
  before update, after update, 
  before delete, after delete,
  after undelete) {

  if (Trigger.isBefore) {
    if (Trigger.isInsert) {

        SalesInvoice_InvoiceTotalValidation.siTotalValidation(Trigger.new, Trigger.oldMap);
    } 
    if (Trigger.isUpdate) {
		SalesInvoice_InvoiceTotalValidation.siTotalValidation(Trigger.new, Trigger.oldMap);

            }
    if (Trigger.isDelete) {

    }
  }

  if (Trigger.IsAfter) {
    if (Trigger.isInsert) {

    } 
    if (Trigger.isUpdate) {

    }
    if (Trigger.isDelete) {

    }
    if (Trigger.isUndelete){

      }
  }
}



Class:
public class SalesInvoice_InvoiceTotalValidation {

    public static void siTotalValidation(List<Sales_Invoice__c> trigSi, Map<Id, Sales_Invoice__c> oldSIMap) {
        Map<Id, Decimal> siTotal   							= new Map<Id, Decimal>(); //Holds the sum of all inserted and updated sales invoices
        Map<Id, Decimal> oppAmount 							= new Map<Id, Decimal>(); //Hold the current amount for the opportunity
        Map<Id, List<Sales_Invoice__c>> oppIdToSalesInvoice = new Map<Id, List<Sales_Invoice__c>>(); //Maps the opp Id to the Sales Invoices for the error message
        Set<Id> oppIdSet		  						    = new Set<Id>(); //Used to create the key for siTotal and oppAmount when calling error
        
        //Filling up maps
        for (Sales_Invoice__c si : trigSi) {
            if (siTotal.containsKey(si.Opportunity__c)) {
                siTotal.put(si.Opportunity__c, si.Total__c + siTotal.get(si.Opportunity__c));
            } else {
                siTotal.put(si.Opportunity__c, si.Total__c);
            } 
            
            if(oppIdToSalesInvoice.containsKey(si.Opportunity__c)) {
                oppIdToSalesInvoice.get(si.Opportunity__c).add(si);
            } else {
                oppIdToSalesInvoice.put(si.Opportunity__c, new List<Sales_Invoice__c>{si});
            }
            
            oppAmount.put(si.Opportunity__c, si.Opportunity__r.Amount);
		}

	      
        oppIdSet = siTotal.keySet();
        for(Id oppId  : oppIdSet) {
            if(siTotal.get(oppId) > oppAmount.get(oppId)){
                for(Sales_Invoice__c si2 : oppIdToSalesInvoice.get(oppId)) {
                    si2.addError('Total of all Sales Invoices cant be greater than opportunity amount. Adjust opp amount first then adjust the Sales Invoices.');
                }
            }
        }
        
        
        
    }
}

 
Fairly new so bear with me. I've written a class that throws an error message for any duplicate emails on Contacts. While writing the test I thought I'd covered everything the original class does however I'm only ending up with 85% code coverage. I'd like to figure out how to get to 100. 

Class (the lines that aren't covered are bolded and underlined):
 
public class Contact_CheckEmail {

    List<Contact> contacts = new List<Contact>();
    
    public Contact_CheckEmail(List<Contact> trigCon){
       contacts = trigCon; 
    }
    

    public void checkEmail(){
    Set<String> emailSet = new Set<String>();
    
    for(Contact c : contacts){
        
        emailSet.add(c.Email);
    
    }
    
    List<Contact> duplicateEmail = [SELECT Email FROM Contact WHERE Email IN: emailSet];
    
    Set<String> duplicateEmailId = new Set<String>();
    
    for(Contact c : duplicateEmail) {
    
        duplicateEmailId.add(c.Email);
    
    }

    for(Contact c: contacts){
        if(duplicateEmailId.contains(c.Email)){
               c.addError('Email already exists.');
        
        }
    
    }
    
}
}


Test Class:
@isTest
public class Test_CheckEmail {
    
    @isTest static void EmailCheckTest(){
        
        Account acc = new Account();
        acc.Name = 'TestAccount';
        insert acc;
        
        List<Contact> contacts = new List<Contact>();
        for( Integer i = 0;i < 1; i++){
            String iString = String.valueof(i);
            Contact myCon = new Contact();
            myCon.LastName = 'iString';
            myCon.AccountId = acc.Id;
            myCon.Email = 'fakeman@fake.com';
            contacts.add(myCon);
        }
        
        try{
        insert contacts;
        }
        catch (Exception e){
            Boolean expectedException = e.getMessage().contains('Email already exists.') ? true : false;
            System.assertEquals(expectedException, true);
        }
        
        List<Contact> contacts2 = new List<Contact>();
        for( Integer i = 0;i < 1; i++){
            String iString = String.valueof(i);
            Contact myCon = new Contact();
            myCon.LastName = 'iString';
            myCon.AccountId = acc.Id;
            myCon.Email = iString + '@fake.com';
            contacts2.add(myCon);
        }
        
        try{
        insert contacts2;
        }
        catch (Exception e){
            Boolean expectedException = e.getMessage().contains('Email already exists.') ? true : false;
            System.assertEquals(expectedException, false);
        }
        
        
        
    }

}