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
HamptonHampton 

Initial term of field expression must be a concrete SObject: MAP<String,Address__c>

Hello:

 

I am getting the above error at Line 15 of the below code. 

 

Here is what I am looking for:

 

(1) Address__c has a field called Release__c

 

(2) There will be multiple Address__c records where Address__c.Release__c.Name = New_Door_Assignment__c.Name

 

(3) Assigned_Address__c is a child to both Address__c and New_Door_Assignment__c

 

(4) What I am trying to do is upon creation of a New_Door_Assignment__c record, to create the multiple child records (Assigned_Address__c) related to both New_Door_Assignment__c and Address__c

 

Here is what I have started and am getting the error above. Any help is moe than appreciated.

 

trigger AddressAssignment on New_Door_Assignment__c (after insert) {

Set<String> releaseName = new Set<String>(); 

for (Release__c release : Trigger.new) {
    {releaseName.add(release.Name);}

Map<String, Address__c> addressMap = new Map<String, Address__c>();
for(Address__c address1 : [Select Name, Unparsed_Address_Formula__c, Release__c from Address__c where Release__c in : releaseName]){
    addressMap.put(address1.Release__c, address1);

List<Assigned_Address__c> newAssignment = new List<Assigned_Address__c>();

    for(New_Door_Assignment__c newRelease : trigger.new) {
        if(addressMap.containsKey.(newRelease.Name))
    newAssignment.add(new Assigned_Address__c(
    Date_Assigned__c = newRelease.Date_Released__c,
    New_Door_Assignment__c = newRelease.ID,
    Rep__c = newRelease.Reps__c));
    }
insert newAssignment;
  }
 } 
} 

 

Thanks,

 

Hampton

Best Answer chosen by Admin (Salesforce Developers) 
ForcepowerForcepower

Hampton,

 

Try removing the period after containsKey: should be:

 

if(addressMap.containsKey(newRelease.Name))

All Answers

ForcepowerForcepower

Hampton,

 

Your trigger is on New_Door_Assignment__c. Wondering why you're doing the following:

for (Release__c release : Trigger.new) {
    {releaseName.add(release.Name);}

HamptonHampton

That must have been a copy and paste error from a previous trigger....

 

I changed that to New_Door_Assignment__c but am still getting the same error at Line 15

ForcepowerForcepower

ok. Is the field Release__c a lookup (and so has an Id rather than a name)? If so,

 

"where Release__c in : releaseName"

 

may be causing some issues as you'trying to compare an id field against a name. You may want to store the Release__c id in the Set rather than the name and try it.

HamptonHampton

In this code, Release__c is a text field on Address__c, which is what is equal to the Name field on New_Door_Assignment__c

trigger AddressAssignment on New_Door_Assignment__c (after insert) {

Set<String> releaseName = new Set<String>(); 

for (New_Door_Assignment release : Trigger.new) {
    {releaseName.add(release.Name);}

Map<String, Address__c> addressMap = new Map<String, Address__c>();
for(Address__c address1 : [Select Name, Unparsed_Address_Formula__c, Release__c from Address__c where Release__c in : releaseName]){
    addressMap.put(address1.Release__c, address1);

List<Assigned_Address__c> newAssignment = new List<Assigned_Address__c>();

    for(New_Door_Assignment__c newRelease : trigger.new) {
        if(addressMap.containsKey.(newRelease.Name))
    newAssignment.add(new Assigned_Address__c(
    Date_Assigned__c = newRelease.Date_Released__c,
    New_Door_Assignment__c = newRelease.ID,
    Rep__c = newRelease.Reps__c));
    }
insert newAssignment;
  }
 } 
} 

 

ForcepowerForcepower

Hampton,

 

Try removing the period after containsKey: should be:

 

if(addressMap.containsKey(newRelease.Name))
This was selected as the best answer
HamptonHampton

Awesome, that worked. Thank you so much for your help!

 

Hampton

ForcepowerForcepower
You're very welcome!
Ram
HamptonHampton

So now I have another question on this. I hope I can properly explain this:

 

I have a field on Assigned_Address__c called Rep_Name__c.

 

I have Rep_One__c, Rep_Two__c, Rep_Three__c, Rep_Four__c and Rep_Five__c on New_Door_Assignment__c

 

I have a custom formula field called Doors_Per_Rep__c on New_Door_Assignment__c

 

What I am hoping to acomplish is:

 

1. Sort the Assigned_Address__c records by Address__c (custom field)

 

2. If Number_of_Doors__c is equal to X, I want New_Door_Assignment__c.Rep_One__c = Assigned_Address__c.Rep_Name__c for the first X number of Address_Assigned__c records

 

3. Repeat the process until all Address_Assigned__c records are assigned using Rep_Two__c, Rep_Three__c, Rep_Four__c and Rep_Five__c if applicaple.

 

I've looked around for help and haven't been able to find much of anything. I assumed I could use the interger i functionality but am not sure where to start.

 

Any suggestions?

 

Current Apex Trigger

 

trigger AddressAssignment on New_Door_Assignment__c (after insert) {

Set<String> releaseName = new Set<String>(); 

for (New_Door_Assignment__c newDoor: Trigger.new) {
    {releaseName.add(newDoor.Name);}

Map<String, Address__c> addressMap = new Map<String, Address__c>();
for(Address__c address1 : [Select ID, Name, Unparsed_Address_Formula__c, Release__c from Address__c where Release__c in : releaseName]){
    addressMap.put(address1.Release__c, address1);

List<Assigned_Address__c> newAssignment = new List<Assigned_Address__c>();

    for(New_Door_Assignment__c newRelease : trigger.new) {
        if(addressMap.containsKey(newRelease.Name))
    newAssignment.add(new Assigned_Address__c(
    Address__c = addressMap.get(newRelease.Name).Unparsed_Address_Formula__c,
    Date_Assigned__c = newRelease.Date_Released__c,
    New_Door_Assignment__c = newRelease.ID,
    Rep__c = newRelease.Reps__c));
    }
insert newAssignment;
  }
 } 
}

 

ForcepowerForcepower

Hampton,

 

I think you'll need something like this:   pseudocode below

 

 

Integer doorsPerRep = newRelease.Doors_Per_Rep__c;

String previousRep = '';

Integer doorAssigned = 0;

String currentRep = newRelease.Rep_One__c;

for (Address_Assigned__c addrAssigned : aaList) {

     if (doorAssigned == doorsPerRep) {

          doorAssigned = 0;

          currentRep = (previousRep == newRelease.Rep_One__c) ? newRelease.Rep_Two__c :

          (previousRep == newRelease.Rep_Two__c) ? newRelease.Rep_Three__c :     

 

          (previousRep == newRelease.Rep_Three__c) ? newRelease.Rep_Four__c :

          (previousRep == newRelease.Rep_Four__c) ? newRelease.Rep_Five__c :

          (previousRep == newRelease.Rep_Five__c) ? newRelease.Rep_One__c : newRelease.Rep_One__c;

     }

     addrAssigned..Rep_Name__c = currentRep;

     doorAssigned++;

}

 

}

 

best,

Ram

HamptonHampton

Thanks Ram. I'm still trying to digest the pseudo-code and what it means.

 

Question - should I write this as a part of the existing trigger or should I write it as a new trigger on the Assigned Address record?

 

Thanks,

 

Hampton

ForcepowerForcepower

Hampton,

 

Yes - it should go into your trigger code - trigger AddressAssignment on New_Door_Assignment__c

 

It is taking the address change records and assigning the first X to Rep 1 and next X to Rep 2 and so on - based on what you indicated.

 

Ram

HamptonHampton

OK, thanks....can you give me some sort of idea of where to put the code? I cannot seem to grasp where it needs to be.

 

Thanks!

 

Hampton

ForcepowerForcepower

Hampton,

 

I have to admit I'm not as familiar with your data model as you are. But I would focus on these lines below. Do you need to pull a bunch of Assigned Address Records for each new door assignment that changed?

 

List<Assigned_Address__c> newAssignment = new List<Assigned_Address__c>();

    for(New_Door_Assignment__c newRelease : trigger.new) {