I have a List and I am querying for 3 values Timecard Id, End date and Company ID. I want to create a set of company id. I am trying to do the following but I am getting error. Here company id is a lookup field and the values are something like this "XYZ solutions". So I have taken Set<String> instead of Set<ID>.

trigger Timecard on pse__Timecard_Header__c (after insert) {

  List<pse__Timecard_Header__c> tc_list = [select Id, pse__End_Date__c, pse__Project__r.pse__Region__r.ffpsai__OwnerCompany__r.Id 
                                             from pse__Timecard_Header__c
                                             where Id IN :Trigger.newMap.KeySet()];
    Set<String> tc_setofId = new Set<String>();
     for (pse__Timecard_Header__c tcId: tc_list)
            String s = tcId.pse__Project__r.pse__Region__r.ffpsai__OwnerCompany__r.Id();
  • What error are you getting? – BarCotter Dec 3 '14 at 15:33
  • This is the error: Method does not exist or incorrect signature: [SOBJECT:c2g__codaCompany__c].Id() – LazyBones Dec 3 '14 at 15:37
  • @sus - That error does not match what you have in your code above, there is not place in that code that I see that has c2g__codaCompany__c – Eric Dec 3 '14 at 15:40

This line:

String s = tcId.pse__Project__r.pse__Region__r.ffpsai__OwnerCompany__r.Id();

Is no valid syntax as a field is not a method. Methods use the () notation.

To get the ID of the OwnerCompany (Lookup field as you suggested) all you need is:

String s = tcId.pse__Project__r.pse__Region__r.ffpsai__OwnerCompany__c;
  • 1
    FYI: Id is a data type so you could declare your Set as: Set<Id>. You may also need some null guards for pse__Project__r and pse__Project__r.pse__Region__r – BarCotter Dec 3 '14 at 15:47
  • 1
    @BarCotter - Valid points. Was only answering the direct question posed. There are all sorts of other things that could be said.... – Eric Dec 3 '14 at 15:55
  • if you can help me here too..this is follow up question to this post salesforce.stackexchange.com/questions/57898/… – LazyBones Dec 3 '14 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.