+ Start a Discussion

Updating Case Owner via Apex

I can't seem to get past this problem. When a user submits a case, I would like for this trigger to check to see if the account has a partner assigned to them and if so, if this partner is part of the partner portal, then assign the case to that partner.  The code that I receive is on the "c.OwnerID = myAccountPartner[0].AccountToId.getUserId();" line.  I receive this error "

Save error: Initial term of field expression must be a concrete SObject: LIST<Case> Reassign.trigger /PartnerCheck/src/triggers line 14 Force.com save problem



 Someone please help.  


trigger Reassign on Case (after insert) {	
		case[] c = trigger.new;	
	// First retrieve submitted users accountID
	contact[] myContact = [Select AccountId FROM contact where Email = :c[0].SuppliedEmail]; 
	//Now see if this account owner is associated with an account partner	
	accountpartner[] myAccountPartner = [Select accountToId FROM accountPartner where accountfromid = :myContact[0].AccountId];
	//if the account partner is a delegated partner then reassign 
	account[] partnerInfo = [Select ispartner FROM account where ID  = :myAccountPartner[0].AccountToId]; 
	if (partnerInfo[0].ispartner==true) { 	 
            c.OwnerID = myAccountPartner[0].AccountToId.getUserId();         


Jia HuJia Hu
You should use "before insert" trigger, ...


Here problem is with basic syntax. You declared “C ” as an array(means list here).

But you are referring it as “c.“ which is cause of the problem.

Once change that to


c[0].OwnerID = myAccountPartner[0].AccountToId.getUserId();

 which will solve your problem.


That was it.  Thanks so much for your help.