//3.2.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; 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 afterfirst(String phoneNumber) { String formatPhoneNumber = phoneNumber.mid(0,2)+'-'+phoneNumber.mid(2,phoneNumber.length()-1); return formatPhoneNumber; } webService static String aftersecond(String phoneNumber) { String formatPhoneNumber = phoneNumber.mid(0,3)+'-'+phoneNumber.mid(3,phoneNumber.length()-1); return formatPhoneNumber; } webService static String afterthird(String phoneNumber) { String formatPhoneNumber = phoneNumber.mid(0,4)+'-'+phoneNumber.mid(4,phoneNumber.length()-1); return formatPhoneNumber; } webService static String getCasesByPhoneNumber(String phoneNumber) { String formatedPhoneNumber = formatPhoneNumber(phoneNumber); String formatedphonewithoutspace=formatPhoneNumberwithoutspace(phoneNumber); string afterFirst=afterfirst(phoneNumber); string aftersecond=aftersecond(phoneNumber); string afterthird=afterthird(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+ '%') OR ContactPhone LIKE : ('%' + afterFirst+ '%') OR ContactPhone LIKE : ('%' + aftersecond+ '%') OR ContactPhone LIKE : ('%' + afterthird+ '%') ]) { 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); string afterFirst=afterfirst(ContactNumber); string aftersecond=aftersecond(ContactNumber); string afterthird=afterthird(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 + '%') OR ContactMobile LIKE: ('%' + formatedphonewithoutspace+ '%') OR ContactMobile LIKE: ('%' + formatedPhoneNumber + '%') OR ContactMobile LIKE: ('%' + afterFirst+ '%') OR ContactPhone LIKE : ('%' + afterFirst+ '%') OR ContactMobile LIKE: ('%' + aftersecond+ '%') OR ContactPhone LIKE : ('%' + aftersecond+ '%') OR ContactMobile LIKE: ('%' + afterthird+ '%') OR ContactPhone LIKE : ('%' + afterthird+ '%') ]) { 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); string afterFirst=afterfirst(phoneNumber); string aftersecond=aftersecond(phoneNumber); string afterthird=afterthird(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+ '%')OR phone LIKE : ('%' + afterFirst+ '%')OR phone LIKE : ('%' + aftersecond+ '%')OR phone LIKE : ('%' + afterthird+ '%') ]) { 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(); 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 getProfileRecordTypesLead(){ List recordTypes = new List(); for(RecordTypeInfo info: Lead.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); string afterFirst=afterfirst(phoneNumber); string aftersecond=aftersecond(phoneNumber); string afterthird=afterthird(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 mobilephone LIKE : ('%' + formatedPhoneNumber + '%') OR homephone LIKE : ('%' + formatedPhoneNumber + '%') OR phone LIKE : ('%' + phoneNumber+ '%') OR otherphone LIKE : ('%' + phoneNumber+ '%') OR mobilephone LIKE : ('%' + phoneNumber+ '%') OR homephone LIKE : ('%' + phoneNumber+ '%') OR phone LIKE : ('%' + afterFirst+ '%') OR otherphone LIKE : ('%' + afterFirst+ '%') OR mobilephone LIKE : ('%' + afterFirst+ '%') OR homephone LIKE : ('%' + afterFirst+ '%') OR phone LIKE : ('%' + aftersecond+ '%') OR otherphone LIKE : ('%' + aftersecond+ '%') OR mobilephone LIKE : ('%' + aftersecond+ '%') OR homephone LIKE : ('%' + aftersecond+ '%') OR phone LIKE : ('%' + afterthird+ '%') OR otherphone LIKE : ('%' + afterthird+ '%') OR mobilephone LIKE : ('%' + afterthird+ '%') OR homephone LIKE : ('%' + afterthird+ '%') 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(); 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); string afterFirst=afterfirst(phoneNumber); string aftersecond=aftersecond(phoneNumber); string afterthird=afterthird(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+ '%') OR MobilePhone LIKE : ('%' + formatedPhoneNumber + '%') OR MobilePhone LIKE : ('%' + phoneNumber + '%')OR MobilePhone LIKE : ('%' + formatedphonewithoutspace+ '%')OR phone LIKE : ('%' + afterFirst+ '%') OR MobilePhone LIKE : ('%' + afterFirst+ '%')OR phone LIKE : ('%' + aftersecond+ '%') OR MobilePhone LIKE : ('%' + aftersecond+ '%')OR phone LIKE : ('%' + afterthird+ '%') OR MobilePhone LIKE : ('%' + afterthird+ '%') ]) { 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; } }