//3.0.0 global class RainbowConnector { webService static String getUserEmail() { return UserInfo.getUserEmail(); } webService static String getMainURL(){ return ApexPages.currentPage().getUrl(); } 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 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 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 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 : ('%' + 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; } 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; } }