//3.1.0 @RestResource(urlMapping='/RainbowConnector/*') global class RainbowConnector { webService static String getUserEmail() { return UserInfo.getUserEmail(); } webService static String getMainURL(){ return ApexPages.currentPage().getUrl(); } @HttpPost webService static String formatPhoneNumberwithoutspace(String phoneNumber) { String formatPhoneNumber = phoneNumber; if (phoneNumber.startsWith('+33')) { formatPhoneNumber = '0' +phoneNumber.mid(3,11); } return formatPhoneNumber; } webService static String formatPhoneNumber(String phoneNumber) { String formatPhoneNumber = phoneNumber; // uncomment the example conversion according the expected result // please also adapt the test method "testFormatPhoneNumber" in the class "RainbowConnectorTest" // By example: conversion for US // input +18171231234 => search (817)123-1234 // if (phoneNumber.startsWith('+1')) { // formatPhoneNumber = '(' + phoneNumber.substring(2, 5) + ')' + phoneNumber.substring(5, 8) + '-' + phoneNumber.substring(8); //} // By example: conversion for SPAIN // input +34123456 => search 0034123456 // if (phoneNumber.startsWith('+34')) { // formatPhoneNumber = '00' + phoneNumber.substring(1); //} //input +923334567891=> search 03 33 45 67 89 1 // By example: conversion for FR //input +33298160029 => search 02 98 16 00 29 if (phoneNumber.startsWith('+33')) { formatPhoneNumber = '0' +phoneNumber.mid(3,1) +' '+ phoneNumber.mid(4,2) +' '+ phoneNumber.mid(6,2)+ ' ' +phoneNumber.mid(8,2)+ ' ' +phoneNumber.mid(10,2); } return formatPhoneNumber; } webService static String getCasesByPhoneNumber(String phoneNumber) { String formatedPhoneNumber = formatPhoneNumber(phoneNumber); String formatedphonewithoutspace=formatPhoneNumberwithoutspace(phoneNumber); List < SObject > objectList = new List(); for (Case objcase: [SELECT SuppliedName, SuppliedPhone,ContactEmail,Subject FROM Case WHERE SuppliedPhone LIKE : ('%' + formatedPhoneNumber + '%') OR SuppliedPhone LIKE : ('%' + phoneNumber+ '%')OR SuppliedPhone LIKE : ('%' + formatedphonewithoutspace+ '%') OR ContactPhone LIKE : ('%' + formatedPhoneNumber + '%') OR ContactPhone LIKE : ('%' + phoneNumber+ '%') OR ContactPhone LIKE : ('%' + formatedphonewithoutspace+ '%') ]) { objectList.add(objcase); } //find in objectList phoneNumber String JSONString = JSON.serialize(objectList); return JSONString; } webService static String getCasesByContactPhone(String ContactNumber) { String formatedPhoneNumber = formatPhoneNumber(ContactNumber); String formatedphonewithoutspace=formatPhoneNumberwithoutspace(ContactNumber); List < SObject > objectList = new List(); for (Case objcase: [SELECT Id,Status, CaseNumber,SuppliedName,SuppliedPhone,ContactEmail,Subject,Contact.name, Contact.phone FROM Case WHERE ContactPhone LIKE: ('%' + ContactNumber+ '%') OR ContactMobile LIKE: ('%' + ContactNumber+ '%')OR ContactPhone LIKE : ('%' + formatedphonewithoutspace+ '%')OR ContactPhone LIKE : ('%' + formatedPhoneNumber + '%') ]) { objectList.add(objcase); } //find in objectList phoneNumber String JSONString = JSON.serialize(objectList); return JSONString; } webService static String getAccountsByPhoneNumber(String phoneNumber) { String formatedPhoneNumber = formatPhoneNumber(phoneNumber); String formatedphonewithoutspace=formatPhoneNumberwithoutspace(phoneNumber); List < SObject > objectList = new List(); for (Account account: [SELECT id, name, phone,BillingAddress,owner.name FROM Account WHERE phone LIKE : ('%' + formatedPhoneNumber + '%') OR phone LIKE : ('%' + phoneNumber+ '%')OR phone LIKE : ('%' + formatedphonewithoutspace+ '%') ]) { objectList.add(account); } //find in objectList phoneNumber String JSONString = JSON.serialize(objectList); return JSONString; } webService static String getAccountsByFirstLastName(String firstlastname) { List < Account > accountList = new List(); for (Account account: [SELECT id, name, phone,BillingAddress ,owner.name FROM Account WHERE name = : firstlastname]) { accountList.add(account); } String JSONString = JSON.serialize(accountList); return JSONString; } webService static String getAccountsByCorrelatorData(String correlatorData) { List < Account > accountList = new List(); // for (Account account: [SELECT id, name, phone, CorrelatorData__c FROM Account WHERE CorrelatorData__c =: //correlatorData]) // { // accountList.add(account); // } String JSONString = JSON.serialize(accountList); return JSONString; } webService static String getAllRecordTypes() { List recordTypeList = new List(); for (RecordType recordTypes : [SELECT Id,Name,SobjectType,Description FROM RecordType ]) { recordTypeList.add(recordTypes); } string JSONString=JSON.serialize(recordTypeList); return JSONString; } webservice static string getProfileRecordTypesCase(){ List recordTypes = new List(); for(RecordTypeInfo info: Case.SObjectType.getDescribe().getRecordTypeInfos()) { if(info.isAvailable() && info.name != 'Master' ) { recordTypes.add(info); } } string JSONString=JSON.serialize(recordTypes); return JSONString; } webservice static string getProfileRecordTypesContact(){ List recordTypes = new List(); for(RecordTypeInfo info: Contact.SObjectType.getDescribe().getRecordTypeInfos()) { if(info.isAvailable() && info.name != 'Master') { recordTypes.add(info); } } string JSONString=JSON.serialize(recordTypes); return JSONString; } webservice static string getProfileRecordTypesAccount(){ List recordTypes = new List(); for(RecordTypeInfo info: Account.SObjectType.getDescribe().getRecordTypeInfos()) { if(info.isAvailable() && info.name != 'Master') { recordTypes.add(info); } } string JSONString=JSON.serialize(recordTypes); return JSONString; } webService static String getContactsByPhoneNumber(String phoneNumber) { String formatedPhoneNumber = formatPhoneNumber(phoneNumber); String formatedphonewithoutspace=formatPhoneNumberwithoutspace(phoneNumber); List < Contact > contactList = new List(); for (Contact contact: [SELECT id, name, email, phone, otherphone, mobilephone, homephone,mailingaddress, account.name FROM Contact WHERE( phone LIKE : ('%' + formatedPhoneNumber + '%') OR otherphone LIKE : ('%' + formatedPhoneNumber + '%') OR //phone =: formatedPhoneNumber OR otherphone =: formatedPhoneNumber OR mobilephone LIKE : ('%' + formatedPhoneNumber + '%') OR homephone LIKE : ('%' + formatedPhoneNumber + '%') OR phone LIKE : ('%' + phoneNumber+ '%') OR otherphone LIKE : ('%' + phoneNumber+ '%') OR //phone =: phoneNumber OR otherphone =: phoneNumber OR mobilephone LIKE : ('%' + phoneNumber+ '%') OR homephone LIKE : ('%' + phoneNumber+ '%') ) OR phone LIKE : ('%' + formatedphonewithoutspace+ '%') OR otherphone LIKE : ('%' + formatedphonewithoutspace+ '%') OR mobilephone LIKE : ('%' + formatedphonewithoutspace+ '%') OR homephone LIKE : ('%' + formatedphonewithoutspace+ '%') ]) { contactList.add(contact); } String JSONString = JSON.serialize(contactList); return JSONString; } webService static String getContactsByFirstLastName(String firstlastname) { List < Contact > contactList = new List(); for (Contact contact: [SELECT id, name, email, phone, otherphone, mobilephone, homephone, account.name FROM Contact WHERE name LIKE : ('%' + firstlastname + '%')]) { contactList.add(contact); } String JSONString = JSON.serialize(contactList); return JSONString; } webService static String getContactsByCorrelatorData(String correlatorData) { List < Contact > contactList = new List(); // for (Contact contact: [SELECT id, name, phone, CorrelatorData__c FROM Contact WHERE CorrelatorData__c =: //correlatorData]) //{ //contactList.add(contact); //} String JSONString = JSON.serialize(contactList); return JSONString; } webService static String getContactsByEmail(String emailContact) { List < Contact > contactList = new List(); for (Contact contact: [SELECT id, name, email, phone, otherphone, mobilephone, homephone FROM Contact WHERE email LIKE : ('%' + emailContact + '%')]) { contactList.add(contact); } String JSONString = JSON.serialize(contactList); return JSONString; } webService static String getContactByRecordId(String recordId) { List < Contact > contactList = new List(); for (Contact contact: [SELECT id, name, email, phone, otherphone, mobilephone, homephone FROM Contact WHERE Id =: recordId]) { contactList.add(contact); } String JSONString = JSON.serialize(contactList); return JSONString; } webService static String getLeadsByPhoneNumber(String phoneNumber) { String formatedPhoneNumber = formatPhoneNumber(phoneNumber); String formatedphonewithoutspace=formatPhoneNumberwithoutspace(phoneNumber); List < SObject > objectList = new List(); for (Lead lead: [SELECT id, name, phone,email,address FROM Lead WHERE phone LIKE : ('%' + formatedPhoneNumber + '%') OR phone LIKE : ('%' + phoneNumber + '%')OR phone LIKE : ('%' + formatedphonewithoutspace+ '%')]) { objectList.add(lead); } String JSONString = JSON.serialize(objectList); return JSONString; } @HttpGet webService static String getRainbowConnectorProfile() { List < User > users = new List(); for (User user : Database.query('Select Id, RainbowConnectorProfile__c FROM User WHERE Id =\'' + UserInfo.getUserId() + '\'')) { users.add(user); } String JSONString = JSON.serialize(users); return JSONString; } webService static void setRainbowConnectorProfile(String userProfile) { SObject userObject = [SELECT Id, RainbowConnectorProfile__c FROM User WHERE Id =: UserInfo.getUserId() LIMIT 1]; userObject.put('RainbowConnectorProfile__c', userProfile); update userObject; } webService static String getTaskByCallId(String callId) { List < SObject > objectList = new List(); for (Task task: [SELECT Id FROM Task where CallObject =: callId]) { objectList.add(task); } String JSONString = JSON.serialize(objectList); return JSONString; } }