• globalsubwnsz globalsubwnsz
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

Does anyone know why my invocable method is not appearing in my Process Builder's list of Apex Classes?

 

Some extra info: I also have a test class with 100% code coverage as well. Any help is greatly appreciated.

 

Here's my class with the invocable method :

 

public class ContactFunnelToSQL {
    @InvocableMethod(label='Contact Funnel to SQL' description='Updates the Funnel to SQL for Opportunity Contact Roles')
    public static void oppContactsToSql(List<Opportunity> myOppsToUpdate) {
      
        List<Opportunity> myOpps = [
            SELECT Id
              FROM Opportunity 
             WHERE Id IN :new Map<Id, Opportunity>(myOppsToUpdate).keySet()
        ];

        Set<Id> oppIds = new Set<Id>();
            
        // Add Opportunity Ids to a set for querying later
        for (Opportunity opp : myOpps){
            if (opp.Id != null) {
                oppIds.add(opp.Id);
            }
        }

        if (oppIds.size() > 0) {    
            // Get the Contact Ids from the Opportunity Contact Roles
            List <OpportunityContactRole> ocrs = [
                SELECT ContactId
                  FROM OpportunityContactRole
                 WHERE OpportunityId IN :oppIds
            ];
            
            if(ocrs.size() > 0) {       
                
                Set<Id> contactIds = new Set<Id>();

                // Add the Contact Ids to a set for querying later
                for (OpportunityContactRole ocr : ocrs) {
                    if (ocr.ContactId != null && !contactIds.contains(ocr.ContactId)) {
                        contactIds.add(ocr.ContactId); 
                    }
                }

                // Get the Opps' Contacts that are not already in SQL, Won, or Disqualified
                List<Contact> oppContacts = [
                    SELECT Id, Funnel__c, Funnel_Status__c, SQL_Reached__c
                      FROM Contact
                     WHERE Id IN :contactIds 
                       AND Funnel__c != 'SQL'
                       AND Funnel__c != 'Won'
                       AND Funnel__c != 'Disqualified'
                ];

                if (oppContacts.size() > 0) {
                    List<Contact> contactsToUpdate = new List<Contact>();

                    // Set the Contacts' funnels to SQL
                    for (Contact oppCon : oppContacts) {
                        oppCon.Funnel__c      = 'SQL';
                        oppCon.SQL_Reached__c = true;
                        contactsToUpdate.add(oppCon);
                    }

                    if (contactsToUpdate.size() > 0) {
                        update contactsToUpdate;
                    }
                }
            }
        }
    }
}