sforce.opencti.runApex() can be to run or execute Apex using OpenCTI in Salesforce.
Sample Code:
Apex:
global class OpenCTIController {
webService static String fetchContacts( String strPhoneNumber ) {
List < Contact > listContacts = new List < Contact >();
listContacts = [
SELECT Id, Name
FROM Contact
WHERE Phone =: strPhoneNumber
];
String JSONString = JSON.serialize( listContacts );
return JSONString;
}
}
Open CTI JavaScript:
sforce.opencti.runApex( {
apexClass : "OpenCTIController",
methodName : "fetchContacts",
methodParams : "strPhoneNumber=1234567890",
callback : function( result ) { console.log( 'Result is ' + JSON.stringify( result ) ) }
} );
Output: