title: Need help in Dynamic SOQL
body: <p>In my code i need to get the object name from the record id and based on the object name, i need to get the field name to add in my query. For now, I have hardcoded the field names, is there a better way to do this. The field in the where clause is a lookup field in the lease__c object.</p>
  <pre><code>public List&lt;SObject&gt; getObjectData(String recordId) {
          String sObjName = Id.valueOf(recordId).getSObjectType().getDescribe().getName();
         String fieldName = '';
          if (sObjName == 'Property__c') {
              fieldName = 'Property__c';
          }
          else if (sObjName == 'Account') {
                   fieldName = 'Account__c';
          }
          string query = 'SELECT Id, Greatest_MRI_Vacate_Date__c FROM Lease__c WHERE' + fieldName + '=: recordId';
  }
  </code></pre>