+ Start a Discussion
ferry.lukitoferry.lukito 

How to access custom object's standard fields? (CreatedBy and Owner)

Hi all,

 

I need help in getting access to custom object's standard fields. The following is my code so far, caused I'm stuck at this point.

 

trigger CheckUniqueITSkill on IT_Skill_Rating__c (before insert) {
    string employeeid = [SELECT EmployeeNumber FROM User WHERE username = :UserInfo.getUserId()].EmployeeNumber;
   
    List<IT_Skill_Rating__c> itSkillRating =
    [SELECT j.IT_Skill__c
     FROM IT_Skill_Rating__c j
     WHERE j.CreatedBy = :employeeid];

    }

 

And this is the error message:

Error: Compile Error: No such column 'CreatedBy' on entity 'IT_Skill_Rating__c'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. at line 5 column 5.

 

What I am trying to do is to create an online rating. So each user will log in and rate their IT skill. The IT skill values will be available from a picklist field. Once the user selected 1 skill, he/she should not be able to use it again. What I am trying to do is to check the current records that user has entered and see if the IT skill has been rated before,

Thanks alot!!!!

Best Answer chosen by Admin (Salesforce Developers) 
_Prasu__Prasu_

CreatedBy is the name of relationship.

You will need to use "CreatedById" in query. And same applies to Owner also.

All Answers

_Prasu__Prasu_

CreatedBy is the name of relationship.

You will need to use "CreatedById" in query. And same applies to Owner also.

This was selected as the best answer
ferry.lukitoferry.lukito

Thanks for the solution Prasanna, it's working now.