+ Start a Discussion
Jon-Michael MurpheyJon-Michael Murphey 

Apex Class works in Full sandbox but not in production

The apex class works in the Full sandbox but when deployed to production it doesnt work. Class is active field names/apis match and correct permissions are set. I need help with this. I tried using the DLRS tool from app exchange but its causing an error that no one can find out why so i tried it in Apex. Please help.. Im needing to count the number of Activites (open/closed) on contacts, the DLRS is workiung for the Tasks but not Events. Please help...see code below


public with sharing class ContactActivityCount {

    public static Boolean didRun = false;
    public static String conPrefix =  Contact.sObjectType.getDescribe().getKeyPrefix();

    /*
    * Takes a set of contact IDs, queries those contacts, and updates the activity count if appropriate
    */
    public static void updateContactCounts(Set<ID> conIds) {

        if (didRun == false) { //We only want this operation to run once per transaction.
            didRun = true;

            //Query all the contacts, including the tasks child relationships
            List<Contact> con = [SELECT ID, Event2cnt__c, (SELECT ID FROM Tasks), (SELECT ID FROM Events) FROM Contact WHERE ID IN :conIds];
            List<Contact> updateCons = new List<Contact>();

            for (Contact o : con) {
                Integer count = o.tasks.size() + o.events.size();

                if (o.Event2cnt__c != count) {
                    o.Event2cnt__c = count;
                    updateCons.add(o); //we're only doing updates to cons that have changed...no need to modify the others
                }
            }

            //Update the appropriate contacts
            try {
                update updateCons;
            } catch (Exception e) {
                //This is controversial. Anything could happen when updating the contact..validation rule, security, etc. The key is we don't
                //want the event update to fail...so we put a try catch around the con update to make sure we don't stop that from happening.
            }
        }
    }

   }
Best Answer chosen by Jon-Michael Murphey
Raj VakatiRaj Vakati
Setup--> developer -- Apex Classes you can see  Compile all classes 

User-added image

 

All Answers

Raj VakatiRaj Vakati
Can you try to compile the code and see if there any issue?
Jon-Michael MurpheyJon-Michael Murphey
Im new to apex, how would i do that?
Raj VakatiRaj Vakati
Setup--> developer -- Apex Classes you can see  Compile all classes 

User-added image

 
This was selected as the best answer
Jon-Michael MurpheyJon-Michael Murphey
no errors