Created
March 22, 2012 09:05
-
-
Save kookoolib/2157250 to your computer and use it in GitHub Desktop.
Sales force Integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Visual Force Page | |
<apex:page controller="ContactController" showheader="false" action="{!pageDetail}"> | |
<apex:detail subject="{!contactId}" relatedList="false"/> | |
</apex:page> | |
//Apex Controller | |
public class ContactController { | |
public string contactId { get; set; } | |
public ContactController() { | |
} | |
public PageReference pageDetail() { | |
String dialNumber; | |
String name; | |
String fromPhone = ApexPages.currentPage().getParameters().get('phoneNumber'); | |
if (fromPhone!=null) { | |
fromPhone= fromPhone.length() <= 10 ? fromPhone : fromPhone.substring(fromPhone.length() - 10); | |
// search Lead and Contact phone number fields | |
List<List<SObject>> results = [FIND :fromPhone IN Phone FIELDS | |
RETURNING Contact(Id,FirstName, LastName,Owner.Phone), Lead(Id,FirstName, LastName,Owner.Phone) | |
LIMIT 1]; | |
// extract the owner phone if there’s a match | |
if (!results[0].isEmpty()) { | |
Contact r = (Contact)results[0][0]; | |
contactId=r.id; | |
//return r.id; | |
//return new PageReference('/'+r.id); | |
} else if (!results[1].isEmpty()) { | |
Lead r = (Lead)results[1][0]; | |
contactId=r.id; | |
//return r.id; | |
//return new PageReference('/'+r.id); | |
} | |
else { | |
Lead r = new Lead(FirstName='Lead', LastName=fromPhone, Email='[email protected]', Company='test',Phone=fromPhone); | |
try{ | |
insert r; | |
}catch(Exception e){ | |
System.debug('System exception ' + e); | |
} | |
contactId=r.id; | |
//return r.id; | |
//return new PageReference('/'+l.id); | |
} | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment