+ Start a Discussion
Andy SAndy S 

Getting Error on Trigger to update field in a custom object from a standard object.

Hi

I am trying to write a trigger and update bidder number field on Bidder object from Bidder number field on Campaign Member Object. I am getting the following error with the below trigger

Error : Initial term of field expression must be a concrete SObject: List<CampaignMember>

trigger sj_BidderUpdate on sj_Bidder__c (after insert) {
set<ID>campmember = new set <ID> ();
for (sj_Bidder__c bid : Trigger.new  )
    CampMember.add (bid.ID);
   
    list<campaignmember> CM = [select ID, sj_Bidder_Number__c from campaignmember];
    list<sj_Bidder__c> BD = new list <sj_Bidder__c> ();
   
    for ( campaignmember Cmem : CM){
        for (sj_Bidder__c bdr : CM.campaignmember__r){
           
            bdr.sj_Bidder_Number__c = CM.sj_Bidder_Number__c;
            BD.add(bdr);
        }
    }
   
   
}
pconpcon
There are a couple things that are wrong with your trigger from an optimization / govenor limit stand point (SOQL inside of a loop for instance), but ignoring those, I think your issue lies (assuming the error you are getting is on the correct line) with the fact that you are referencing campaignmember__r without querying it in inside your CM query.  Another confusing bit is that you are making the same query over and over with no reference to any additional filter criteria.

You say that you are trying to update the "bidder number field" on the bidder object.  Can you please give some more information about how a campaignmember and bidder object are connected in your data model, as well as exactly which line you are seeing the error.

NOTE: In the future, please use the "Add a code sample" button when adding your code to increase readability.
Jen BennettJen Bennett
The issue is your first for loop is using cmem as the variable name but then you are setting bdr.sj_Bidder_Number__c = CM.sj_Bidder_Number__c instead of cmem.sj_Bidder_Number__c as well as the other issues that pcon mentioned.