i am facing this problem too.i have create a rest service that will check the lead and contact in salesforce if lead or contact is exists then send rest response along with object type.Please suggest me how to do this??? when i use gettype() method then following error comes "Error: Compile Error: Variable does not exist: Company at line 37 column 43"
REST SERVICE :::
@RestResource(urlMapping='/1.0/Persons/*')
global class SQUser
{
@HttpGet
global static String CheckLead()
{
String EmailID = RestContext.request.params.get('Email_id');
LIST<Lead> ledID = [Select ID from Lead where Email=:EmailID LIMIT 1];
LIST<Contact> conID= [Select ID from Contact where Email=:EmailID LIMIT 1];
if(ledID.size()>0)
{
return ledID[0].ID;
}
else if(conID.size()>0)
{
return 'ContactID '+ conID[0].ID;
}
else
{
return 'No record found either for Lead or contact.';
}
}
@HttpPost
global static String CreateRecord()
{
Lead ledID = new Lead();
ledID.FirstName = RestContext.request.params.get('Fist_nm');
ledID.LastName = RestContext.request.params.get('Last_nm');
ledID.Phone = RestContext.request.params.get('Phone');
ledID.Email = RestContext.request.params.get('Email');
ledID.Company= RestContext.request.params.get('Company');
insert ledID;
Schema.DisplayType myType = ledID.get(Company).getDescribe().getType();
return 'Newly Lead Created ' +ledID.ID;
}
}