Skip to content

Instantly share code, notes, and snippets.

@kookoolib
Created March 22, 2012 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kookoolib/2157250 to your computer and use it in GitHub Desktop.
Save kookoolib/2157250 to your computer and use it in GitHub Desktop.
Sales force Integration
//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='example@example.com', 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