You need to sign in to do that
Don't have an account?
Help with createdby.id in code
I am working on a project that I need to compare one item to another based on a createdby.id. Here is the code I have written, but for some reason it does not find the createdby.id of the initial object. Here is the code I have.
Set<ID> cbid = new Set<ID>();
for (ChargentSFA__Transaction__c cb : trigger.new) {
cbid.add(cb.createdby.id);
}
timeclock__c tm = [select id, name from Timeclock__c where in_out_day_today__c=1 and in_out_month_this_month__c=1 and in_out_year_this_year__c=1 and Out_Date_Time__c=false and createdby.id in :cbid limit 1];
It is one word, niet CreatedBy.Id, unless you have a lookup/master relatoin to the user object which you named CreatedBy, but that would amaze me.
All Answers
It is one word, niet CreatedBy.Id, unless you have a lookup/master relatoin to the user object which you named CreatedBy, but that would amaze me.
Thank you, Thank you, Thank you. I am pretty new to this and appreciate the help.
As a clarification, CreatedBy.Id is valid, but only if you query for it. CreatedBy is of the type Schema.SObject, and will be populated if you query for it:
But in this case is unnecessary, because the previous post advises that you use CreatedById instead of CreatedBy.Id, which is the correct answer. There are times when you might use the "non-ID" form, especially when you're doing something like this:
This is a trivial example you'd probably never use, but if you find yourself needing a parent's value and you want to save a SOQL query, you can use this method.