• Andrey Vyshinskiy
  • NEWBIE
  • 20 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 8
    Replies
I need to update an SalesforceIsTerrible apex trigger, but I never did it before. Does anybody know the steps to do this?

Best,
Andrey
Hi guys,
I'm getting this message and our sales team cant log in the calls/tasks they make in SFDC. Does anybody know how to fix this? 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger SalesforceIsTerrible caused an unexpected exception, contact your administrator: SalesforceIsTerrible: execution of BeforeInsert caused by: System.DmlException: Update failed. First exception on row 0 with id 00Tf100002NostKEAR; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, TasksToOpps: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.TasksToOpps: line 40, column 1: []: Trigger.SalesforceIsTerrible: line 27, column 1

The code for the 'TaskToOpps" is below, I not sure how to fix this.


trigger TasksToOpps on Task (before insert, before update) {
            
        /***************
        * Variables
        ***************/
        list<Task> l_Tasks = new list<Task>(); // Tasks we'll be updating
        set<ID> s_ContactIDs = new set<ID>(); // Set of Contact IDs
        set<ID> s_AccountIDs = new set<ID>(); // Set of Account IDs
        set<ID> s_CCAccountIDs = new set<ID>(); // Set of Account IDs of Current Clients
        
        /***************
        * Get all the nerds we reach out to 
        ***************/
        for(Task t:Trigger.new) {
             
            // Add Task to working list and collect the Contact ID
            if (t.WhatId == null &&(t.Type == 'Email' | t.Type =='ClearSlide Email Pitch') && t.WhoId != null) {
                // only for Contacts
                if (String.valueOf(t.WhoId).startsWith('003')){
                    l_Tasks.add(t);
                    s_ContactIDs.add(t.WhoId);
                    System.debug('WhoId:' + t.WhoId);
                }
            }
        }
        System.debug(s_ContactIDs);
        
        //Where do you work
        map<ID, Account> map_cID_to_aID = new map<ID, Account>();
            for (Contact c:
                [SELECT ID, Account.id, Account.name, Account.Account_Status__c
                FROM Contact
                Where Id in :s_ContactIDs
                ]){
                map_cID_to_aID.put(c.ID, c.Account);
                }
        System.debug(map_cID_to_aID);
        
        for (ID c:s_ContactIDs) {
            s_AccountIDs.add(map_cID_to_aID.get(c).Id);
        }
        System.debug(s_AccountIDs);
        
        for (ID cc:s_ContactIDs) {
            if (map_cID_to_aID.get(cc).Account_Status__c == 'Current Client'){
                s_CCAccountIDs.add(map_cID_to_aID.get(cc).Id);
            }
        }
        System.debug(s_CCAccountIDs);
        
        // Maps Account ID to an Opportunity ID
        map<ID, ID> map_aID_to_oID = new map<ID, ID>();
            // Query for the Contact's Open Opportunities. Sort by CloseDate DESC so the Task gets assigned to the earliest Opportunity as it loops
            for (Opportunity o:[select Id, AccountId
                               from Opportunity 
                               where AccountId in :s_AccountIDs 
                               AND Opportunity.IsClosed = false
                               order by Opportunity.CloseDate DESC
                               ]) {
                map_aID_to_oID.put(o.AccountId, o.Id);
            }
        System.debug(map_aID_to_oID);
        
        for (Task t:l_Tasks) {
            if (map_aID_to_oID.get(map_cID_to_aID.get(t.WhoId).id) == null && s_CCAccountIDs.contains(map_cID_to_aID.get(t.WhoId).id)== False){
                System.debug(t);
                System.debug(t.OwnerId);
                System.debug(t.Account);
                System.debug(s_CCAccountIDs.contains(map_cID_to_aID.get(t.WhoId).id));
                //need to put in Jess and My IDs once I am done testing. Confirmed to work though.
                if (t.OwnerId != '005j000000CFBjr' && t.OwnerId != '005j000000BlMOj'){
                    Opportunity opp = new Opportunity();
                    opp.AccountId = map_cID_to_aID.get(t.WhoId).Id;
                    opp.name = map_cID_to_aID.get(t.WhoId).name;
                    opp.StageName = '0 - Cold';
                    opp.OwnerId = t.OwnerId;
                    opp.CloseDate = system.today().addMonths(3);
                    System.debug(opp);
                    insert opp;
                    map_aID_to_oID.put(opp.AccountID, opp.Id);
                   }
            
            }
        }
        
        for (Task t:l_Tasks) {
            if (map_cID_to_aID.get(t.WhoId) != null) {
                System.debug('first map check');
                if (map_aID_to_oID.get(map_cID_to_aID.get(t.WhoId).Id) != null){
                    System.debug('Second map check');
                    System.debug(map_aID_to_oID.get(map_cID_to_aID.get(t.WhoId).Id));
                    t.WhatId = map_aID_to_oID.get(map_cID_to_aID.get(t.WhoId).Id);
                }
            }
        }
        
     
}

 
I'm getting this message and our sales team cant log in the calls they make. Does anybody know how to fix this? 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger SalesforceIsTerrible caused an unexpected exception, contact your administrator: SalesforceIsTerrible: execution of BeforeInsert caused by: System.DmlException: Update failed. First exception on row 0 with id 00Tf100002NostKEAR; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, TasksToOpps: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.TasksToOpps: line 40, column 1: []: Trigger.SalesforceIsTerrible: line 27, column 1
I trying to remove the following Apex Trigger TasksToOpps from my org. How can I do that? Right now I have no way to remove it or deactivate it. User-added image
One of our sales folks user who tried to create a task on a contact level got this message : Apex trigger SalesforceTrigger Error caused an unexpected exception. First error: cannot_insert_update_activate_entitiy, taskstoopps: exectionbeforeupdae casused by> System.NullPointerException . 

How do I fix this, I'm new to Salesforce. Any feedback would help. 
Hi guys,
I'm getting this message and our sales team cant log in the calls/tasks they make in SFDC. Does anybody know how to fix this? 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger SalesforceIsTerrible caused an unexpected exception, contact your administrator: SalesforceIsTerrible: execution of BeforeInsert caused by: System.DmlException: Update failed. First exception on row 0 with id 00Tf100002NostKEAR; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, TasksToOpps: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.TasksToOpps: line 40, column 1: []: Trigger.SalesforceIsTerrible: line 27, column 1

The code for the 'TaskToOpps" is below, I not sure how to fix this.


trigger TasksToOpps on Task (before insert, before update) {
            
        /***************
        * Variables
        ***************/
        list<Task> l_Tasks = new list<Task>(); // Tasks we'll be updating
        set<ID> s_ContactIDs = new set<ID>(); // Set of Contact IDs
        set<ID> s_AccountIDs = new set<ID>(); // Set of Account IDs
        set<ID> s_CCAccountIDs = new set<ID>(); // Set of Account IDs of Current Clients
        
        /***************
        * Get all the nerds we reach out to 
        ***************/
        for(Task t:Trigger.new) {
             
            // Add Task to working list and collect the Contact ID
            if (t.WhatId == null &&(t.Type == 'Email' | t.Type =='ClearSlide Email Pitch') && t.WhoId != null) {
                // only for Contacts
                if (String.valueOf(t.WhoId).startsWith('003')){
                    l_Tasks.add(t);
                    s_ContactIDs.add(t.WhoId);
                    System.debug('WhoId:' + t.WhoId);
                }
            }
        }
        System.debug(s_ContactIDs);
        
        //Where do you work
        map<ID, Account> map_cID_to_aID = new map<ID, Account>();
            for (Contact c:
                [SELECT ID, Account.id, Account.name, Account.Account_Status__c
                FROM Contact
                Where Id in :s_ContactIDs
                ]){
                map_cID_to_aID.put(c.ID, c.Account);
                }
        System.debug(map_cID_to_aID);
        
        for (ID c:s_ContactIDs) {
            s_AccountIDs.add(map_cID_to_aID.get(c).Id);
        }
        System.debug(s_AccountIDs);
        
        for (ID cc:s_ContactIDs) {
            if (map_cID_to_aID.get(cc).Account_Status__c == 'Current Client'){
                s_CCAccountIDs.add(map_cID_to_aID.get(cc).Id);
            }
        }
        System.debug(s_CCAccountIDs);
        
        // Maps Account ID to an Opportunity ID
        map<ID, ID> map_aID_to_oID = new map<ID, ID>();
            // Query for the Contact's Open Opportunities. Sort by CloseDate DESC so the Task gets assigned to the earliest Opportunity as it loops
            for (Opportunity o:[select Id, AccountId
                               from Opportunity 
                               where AccountId in :s_AccountIDs 
                               AND Opportunity.IsClosed = false
                               order by Opportunity.CloseDate DESC
                               ]) {
                map_aID_to_oID.put(o.AccountId, o.Id);
            }
        System.debug(map_aID_to_oID);
        
        for (Task t:l_Tasks) {
            if (map_aID_to_oID.get(map_cID_to_aID.get(t.WhoId).id) == null && s_CCAccountIDs.contains(map_cID_to_aID.get(t.WhoId).id)== False){
                System.debug(t);
                System.debug(t.OwnerId);
                System.debug(t.Account);
                System.debug(s_CCAccountIDs.contains(map_cID_to_aID.get(t.WhoId).id));
                //need to put in Jess and My IDs once I am done testing. Confirmed to work though.
                if (t.OwnerId != '005j000000CFBjr' && t.OwnerId != '005j000000BlMOj'){
                    Opportunity opp = new Opportunity();
                    opp.AccountId = map_cID_to_aID.get(t.WhoId).Id;
                    opp.name = map_cID_to_aID.get(t.WhoId).name;
                    opp.StageName = '0 - Cold';
                    opp.OwnerId = t.OwnerId;
                    opp.CloseDate = system.today().addMonths(3);
                    System.debug(opp);
                    insert opp;
                    map_aID_to_oID.put(opp.AccountID, opp.Id);
                   }
            
            }
        }
        
        for (Task t:l_Tasks) {
            if (map_cID_to_aID.get(t.WhoId) != null) {
                System.debug('first map check');
                if (map_aID_to_oID.get(map_cID_to_aID.get(t.WhoId).Id) != null){
                    System.debug('Second map check');
                    System.debug(map_aID_to_oID.get(map_cID_to_aID.get(t.WhoId).Id));
                    t.WhatId = map_aID_to_oID.get(map_cID_to_aID.get(t.WhoId).Id);
                }
            }
        }
        
     
}

 
I'm getting this message and our sales team cant log in the calls they make. Does anybody know how to fix this? 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger SalesforceIsTerrible caused an unexpected exception, contact your administrator: SalesforceIsTerrible: execution of BeforeInsert caused by: System.DmlException: Update failed. First exception on row 0 with id 00Tf100002NostKEAR; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, TasksToOpps: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.TasksToOpps: line 40, column 1: []: Trigger.SalesforceIsTerrible: line 27, column 1
I trying to remove the following Apex Trigger TasksToOpps from my org. How can I do that? Right now I have no way to remove it or deactivate it. User-added image
One of our sales folks user who tried to create a task on a contact level got this message : Apex trigger SalesforceTrigger Error caused an unexpected exception. First error: cannot_insert_update_activate_entitiy, taskstoopps: exectionbeforeupdae casused by> System.NullPointerException . 

How do I fix this, I'm new to Salesforce. Any feedback would help.