1

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;    
 }    
}
1
  • This isn't really an answer. It would be better to post this as a question.
    – Jagular
    Commented Aug 6, 2014 at 14:01

1 Answer 1

1
Schema.Lead.Company.getDescribe().getType();

You're trying to reference a symbol (company) that doesn't exist.

If you need dynamic code:

Schema.getGlobalDescribe().get(objectName).getDescribe().fields.getMap().get(fieldName).getDescribe().getType();

Where objectName and fieldName are strings, such as 'Lead' and 'Company'.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .