void automation.send_RC_SMS_to_contact_of_deal(string dealID)
{
// Fetch the deal record by its ID
dealRecord = zoho.crm.getRecordById("Deals", dealID);
// Check if the Contact lookup field is available in the deal record
if(dealRecord.get("Contact_Name") != null)
{
// Get the Contact ID from the Deal
contactId = dealRecord.get("Contact_Name").get("id");
contactRecord = zoho.crm.getRecordById("Contacts", contactId); // Fetch the Contact record
// Check if the contact exists and has an ID
if(contactRecord.get("id") != null)
{
// Check if SMS_Opt_Out is false (unchecked)
if(contactRecord.get("SMS_Opt_Out") == false)
{
contactFirstName = ifnull(contactRecord.get("First_Name"), "");
contactMobile = contactRecord.get("Mobile");
if(contactMobile != null)
{
// Get the Deal Owner (optional based on your needs)
dealOwner = dealRecord.get("Owner");
ownerRecord = zoho.crm.getRecordById("users", dealOwner.get("id"));
// Retrieve the RC Account ID from the user (Owner) record
AccountId = "";
if (ownerRecord.get("users") != null)
{
AccountId = ownerRecord.get("users").get(0).get("RC_Account_ID");
}
// Define the extension ID, from number, and the message content
ExtensionId = ""; // Optional Extension ID
FromNumber = ""; // Optional From Number (use if different from account number)
MsgText = "Hi " + contactFirstName + ", just checking in to make sure you received my proposal. Let me know if you have any questions. - Matt Kakuk";
// Send the SMS using the correct API call
resp = multiuserringcentralmessagingextension.sendRcSms(AccountId, ExtensionId, FromNumber, contactMobile, MsgText);
info resp; // Log the response for debugging
}
else
{
info "Contact does not have a mobile number.";
}
}
else
{
info "Contact has opted out of SMS communication.";
}
}
else
{
info "Contact record not found.";
}
}
else
{
info "No contact associated with this deal.";
}
}