You need to sign in to do that
Don't have an account?

For loop & query for custom object
Hello,
I am new at this so please bare with me but I am trying to create an Apex class with a query in a custom object.
The custom Object is called "SIM"
I basically want to use a For loop to sum a field for all records under this object that have the same two fields
The two fields are called:
"Account" which is a masterdetail relationship lookup field to the Standard Account Object
"Item" which is a masterdetail relationship lookup field to a Custom Object called "INV"
However to do this I need to first retrieve the account ID or name. I tried somehting like this:
String accountId = SIM__c.Account__c.getId();
and I got this error:
![]() | Error: Compile Error: Method does not exist or incorrect signature: [Schema.SObjectField].getId() |
Any Ideas?
I think the code would be different for the two since one is Master/detail lokup to a standard object and the other to a custom object. I need help for both of them.
Thanks in advance!!
As account is standard object here is the way you can access acount id
String accountId = SIM__c.Account.id;
The account's ID value would be simply the contents of the field:
Lookup fields only appear to reference the name of the record it looks up when using the graphical interface; non-technical users appreciate being able to see John Doe instead of 003X000000aD3Fz when they view a record on their screen or in a report. The Salesforce database always stores just a link to the record (hence the term "lookup field") by using that record's unique ID value; this value is what Apex Code and the API see when you reference the field's value.