0

Code:

trigger AssignCloseOppTeamMember on OpportunityTeamMember (after insert) {
    List<Opportunity> OpportunityList = new List<Opportunity>();
    Map<Id, Id> OppIdOppMemberIdMap = new Map<Id, Id>();

    for(OpportunityTeamMember OpportunityTeamMemberObj: Trigger.New){
        if(OpportunityTeamMemberObj.TeamMemberRole =='Portfolio Developer')

            OppIdOppMemberIdMap.put(OpportunityTeamMemberObj.OpportunityId , OpportunityTeamMemberObj.Id);
    }

    for(Opportunity opportunityObj : [Select Id, LocalPortfolioDeveloper__c from Opportunity where Id IN: OppIdOppMemberIdMap.keyset()]){
        if(OppIdOppMemberIdMap.Containskey(opportunityObj.Id)){
            opportunityObj.LocalPortfolioDeveloper__c= OppIdOppMemberIdMap.get(opportunityObj.Id).UserId;
            OpportunityList.add(opportunityObj);
            }
        }
    update OpportunityList;

    }

Error Message:

Initial term of field expression must be a concrete SObject: Id at line 13 column 95

0

You have declared

Map<Id, Id> OppIdOppMemberIdMap = new Map<Id, Id>();

And, preparing the map like this:

OppIdOppMemberIdMap.put(OpportunityTeamMemberObj.OpportunityId , OpportunityTeamMemberObj.Id);

so far good.

Error in this line

opportunityObj.LocalPortfolioDeveloper__c= OppIdOppMemberIdMap.get(opportunityObj.Id).UserId;

Basically,

OppIdOppMemberIdMap.get(opportunityObj.Id) returns the Id of OpportunityTeamMemberObj record.

Now, Id.userId doesn't make any sense and it returns the error

Correct code will be:

for(Opportunity opportunityObj : [Select Id, LocalPortfolioDeveloper__c from Opportunity where Id IN: OppIdOppMemberIdMap.keyset()]){
    if(OppIdOppMemberIdMap.Containskey(opportunityObj.Id)){
        opportunityObj.LocalPortfolioDeveloper__c= OppIdOppMemberIdMap.get(opportunityObj.Id);
        OpportunityList.add(opportunityObj);
        }
    }
update OpportunityList;

}

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.