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
CarlaMartinez.ax1388CarlaMartinez.ax1388 

Trigger - Auto-update lookup fields from picklist value on custom object

I am pretty new to APEX and with help wrote a trigger to auto-update a lookup field based on selecting a value on a picklist field on the account object. Now I am trying to replictae it on a custom object and the code below is giving me errors. 

Error: Compile Error: unexpected token: 'Map" at line 1 column 14

 

public static Map<String, List<Primary_Sales_Rep__c>> filterPrimarySalesRepsWithChangedVerticals(List<Primary_Sales_Rep__c> incomingPrimarySalesReps,
Map<Id, PrimarySalesRep__c>oldPrimarySalesRepIdToOldPrimarySalesRep)
{

Map<String, List<PrimarySalesRep__c>> verticalNametoPrimarySalesRepList = new Map<String, List<PrimarySalesRep__c>>();

//For all PrimarySalesRep that were sent to out Trigger
for(PrimarySalesRep__c incomingPrimarySalesRep : incomingPrimarySalesReps)
{
//Change conditions
//1.Vertical is now being set
//2. Vertical is being changed

Boolean isChanged
Boolean isInsert - oldPrimarySalesRepIdToOldPrimarySalesRep == null;
PrimarySalesRep__c oldPrimarySalesRep = isInsert ? null : oldPrimarySalesRepIdToOldPrimarySalesRep.get(incomingPrimarySalesRep.Id);

isChanged = (( isInsert && incomingPrimarySalesRep__c.Vertical_Major__c != null)
||(!isInsert && oldPrimarySalesRep__c.Vertical_Major__c != incomingPrimarySalesRep__c.Vertical_Major__c));

if(isChanged)
{
if(!verticalNameToPrimarySalesRepList.containsKey( incomingPrimarySalesRep__c.Vertical_Major__c))
verticalNameToPrimarySalesrepList.put(incomingPrimarySalesRep__c.Vertical_Major__c, new List<PrimarySalesRep__c>));

verticalNameToPrimarySalesrepList.get( incomingPrimarySalesrep__c.Vertical_Major__c).add(incomingPrimarySalesrep__c);
}

}
return verticalNametoPrimarySalesRepList;
}

 

hemantgarghemantgarg

Is it trigger code or a static method in trigger/class ?

CarlaMartinez.ax1388CarlaMartinez.ax1388

It's a method in a class