I am getting an error with a class. Normal error telling me to allow access for this new Profile - probably not put the class in the profile Class Access... But when I go to look, the class is not available in neither list.
Error message:
Insert failed. First exception on row 0; first error: CANNOT_EXECUTE_FLOW_TRIGGER, We can't save this record because the “SMS Chatter Notification” process failed. Give your Salesforce admin these details. Profile does not have access to: getemployeefromnumber Error ID: 1119766178-30139 (477012206): []
Salesforce Admin profile has no issues. I've never done an Invocable Method so is this normal?
Adding class:
/*
* SG Added this class : Gets the employee name and record from teh number back from Twilio. Must only return where contact.recordtype = Emploee
* then we want to send a message to the person who is sending the messages.
*/
public class getEmployeefromNumber {
@InvocableMethod(label='Get Employees' description='Get the employee who sent last message and posts a chatter message TO THAT USER.' category='TwilioSF__Message__c')
public static void getEmployeefromNumber(List<id> pMessageIDs) {
//get all message numbers
list <TwilioSF__Message__c> paramMessages = [select id, TwilioSF__Body__c, OwnerId, TwilioSF__From_Number_Unformatted__c
from TwilioSF__Message__c where id in : pMessageIDs];
// set variables
list<FeedItem> Posts = new list <FeedItem>();
set<string> pMobileNumbers = new set<string>();
set<id> empIDs = new set<id>();
set<id> userIDs = new set<id>();
map<string,string> EmpNames = new map<string,string>();
map<string,id> MessageToUsers = new map<string,id>();
map<string,string> fromNumbertoMessage = new map<string,string>();
system.debug('\n _____> SEAN pMessageIDs = ' + pMessageIDs);
system.debug('\n _____> SEAN paramMessages = ' + paramMessages);
//get the numbers from the current messages
for(TwilioSF__Message__c runMess :paramMessages){
pMobileNumbers.add(runMess.TwilioSF__From_Number_Unformatted__c);
fromNumbertoMessage.put(runMess.TwilioSF__From_Number_Unformatted__c, runMess.TwilioSF__Body__c);
}
system.debug('\n _____> SEAN pMobileNumbers = ' + pMobileNumbers);
//get the employee from the number
list <contact> allEmps = [select id, name, MobilePhone from contact where RecordTypeId = '0121I000000G0yDQAS' and MobilePhone in: pMobileNumbers];
system.debug('\n _____> SEAN allEmps = ' + allEmps);
// get a map of employee and their number and all employees who sent messages
for(contact employee : allEmps){
EmpNames.put(employee.MobilePhone, employee.name);
system.debug('\n SEAN EmpNames = ' + EmpNames);
empIDs.add(employee.id);
system.debug('\n SEAN empIDs = ' + empIDs);
}
// get the user who sent the last message to those employees above
if(allEmps.size()>0){
list <TwilioSF__Message__c> messages = [select id, TwilioSF__Body__c, OwnerId, TwilioSF__To_Number_Unformatted__c
from TwilioSF__Message__c
where TwilioSF__To_Number_Unformatted__c = :pMobileNumbers order by CreatedDate desc]; // age of message to limit the results?
system.debug('\n SEAN messages = '+messages);
// get a map of the numbers to the last users who sent a message and the list of all users who sent messages
for(TwilioSF__Message__c message : messages){
if(!MessageToUsers.containsKey(message.TwilioSF__To_Number_Unformatted__c)){
System.debug('=======phonenumber====='+message.TwilioSF__To_Number_Unformatted__c);
System.debug('=======phonenumber====='+message.OwnerID);
MessageToUsers.put(message.TwilioSF__To_Number_Unformatted__c, message.OwnerID);
}
userIDs.add(message.OwnerID);
}
system.debug('\n SEAN MessageToUsers = '+MessageToUsers);
system.debug('\n SEAN userIDs = '+userIDs);
Map<ID, User> UserNames = new Map<ID, User>([SELECT Id, Name FROM User]);
list<user> Users = [select Name from user where id in: userIDs];
// loop through each number and send a post to the last person who sent a message
// for each message number
for(string fromNumber :pMobileNumbers){
System.debug('======empnames====='+EmpNames.get(fromNumber));
System.debug('======1====='+MessageToUsers.get(fromNumber));
System.debug('======2====='+UserNames.get(MessageToUsers.get(fromNumber)));
System.debug('======3====='+UserNames.get(MessageToUsers.get(fromNumber)).Name);
System.debug('======4======='+fromNumbertoMessage.get(fromNumber));
string body = EmpNames.get(fromNumber)+' responded to '+UserNames.get(MessageToUsers.get(fromNumber)).Name+'\'s outreach: ' + fromNumbertoMessage.get(fromNumber) ;// + message.TwilioSF__Body__c;
Posts.add(postFeed(MessageToUsers.get(fromNumber), body));
}
//insert the post
insert Posts;
}
}
public static FeedItem postFeed(id pUserID, string pBody){
FeedItem post = new FeedItem();
post.ParentId = pUserID;
post.Body = pBody;
return post;
}
}