function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SF DEVSF DEV 

Compile Error: Initial term of field expression must be a concrete SObject

Compile Error: Initial term of field expression must be a concrete SObject: String at line 20 column 59

 

trigger Update_AccountID on Account (after insert,after update) {

public list<AccountID__c > AID =new list<AccountID__c >();
public Map<string,String> Map_Types=new Map<string,String>();
set<string> Typevalue=new set<string>();
for(account a1:trigger.new){
Typevalue.add(a1.type);
}
Account_Running_Number__c []ARN_ids=[select Id,Running_Number__c,Type__c from Account_Running_Number__c where Type__c in:Typevalue];
for(Account_Running_Number__c AR1:ARN_ids){
Map_Types.put(AR1.Type__c,AR1.Type__c);
}

for(Account a2:trigger.new){
for(Account a3:trigger.old)
{
if(a2.Type=='Tour Agent' && a3.Type!='Tour Agent')
{
AccountID__c t1 = new AccountID__c();
t1.Account_Id__c='TA'+Map_Types.get(a2.Type).Running_Number__c;
t1.Type__c=a2.Type;
AID.add(t1);
}
}
}
Insert AID;
}

 

 

Compilation error giving how to solve!!!, The way i used MAP is some where wrong. Can any one suggest.

Best Answer chosen by Admin (Salesforce Developers) 
ForceMantis (Amit Jain)ForceMantis (Amit Jain)

Replace this line in code:

 

Map_Types.put(AR1.Type__c,AR1.Type__c);

 

with this one and I am sure it will fix the problem.

 

Map_Types.put(AR1.Type__c,AR1);

All Answers

ForceMantis (Amit Jain)ForceMantis (Amit Jain)

Your map declaration:

public Map<string,String> Map_Types=new Map<string,String>();

 

You put values in map:

Map_Types.put(AR1.Type__c,AR1.Type__c);

 

Access value from map:

Map_Types.get(a2.Type).Running_Number__c;

 

 

Map type is String, String which means key is string value is string. While you put value in map you put string as key and value.

 

While accessing data from map you are accessing map value as object: object.property. Either put wrong value in map or you are accessing it incorrectly. It dependes on what exactly you want to do.

Vinit_KumarVinit_Kumar

Can you tell me how object are related and what you want to achieve here and then I can help you out.

SF DEVSF DEV

I have Two objects 

 

1) Account

2) runningNumber

 

They both are not related, But they got same field names as "TYPE"

 

From running i need number field value with same type of acct, and then update the one of the field in Account.

ForceMantis (Amit Jain)ForceMantis (Amit Jain)

Replace this line in code:

 

Map_Types.put(AR1.Type__c,AR1.Type__c);

 

with this one and I am sure it will fix the problem.

 

Map_Types.put(AR1.Type__c,AR1);

This was selected as the best answer
SF DEVSF DEV

ok, will work on the same.