Problem statement - To check if the record has Opted In or not
Go to Setup
In the quick find/search box, type "object"
Now select object
Click on SMS History
Now go to the "Validation Rules" section
Click on New
Write a Rule name
Ensure that the "Active" checkbox is marked as True.
Now add the following formula and replace the colored part (mentioned below)
In the "Error Message" type true (you can add any value here, it will show a generic error while sending out SMS to opted out record)
AND( smagicinteract__Contact__r.SMS_Opt_In__c , smagicinteract__Contact__r.MobilePhone = smagicinteract__PhoneNumber__c )
smagicinteract__Contact__r.SMS_Opt_In__c = the opt In field . - (you need to replace this with the API name of your opt In field)
smagicinteract__Contact__r.MobilePhone = the related phone field . - (you need to replace this with the API name of your phone field)