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
EricSSHEricSSH 

Method does not exist or incorrect signature: Apex Trigger

Some quick background of what Im trying to do..

The following is my Apex Trigger. It is a validation Trigger on Sampling_c which will validate that Country_c is a Valid country using Validation_country_c. When it validates Country_c it will look into State_province_c and will then validate that it is actually a state So .. If Country_c = US and State_province_c = CA then we are okay. But IF Country_c = US and State_province_c = ZZ221(whatever) it should fail. Now these condition checks only triggers when Override_c = 'Yes'.

I've also written a test class that is ignoring some lines, but  I will work one issue at a time.

validCountries.get( obj.Transportation_Zone__c,obj ); This line is breaking, but I believe its happening because of 

--

Map<String, Validation_Country__c> validCountries = new Map<String, Validation_Country__c>();

The Error that I'm getting is --
Method does not exist or incorrect signature: [MAP<String,Validation_Country__c>].get(String, SOBJECT:Validation_Country__c)

Can anyone give me some guidance?

trigger OverrideTrigger on Sampling__c (before insert,before update) {

// Top level map is keyed by Country. Inner Map is keyed by Region
    Map<String, Validation_Country__c> validCountries = new Map<String, Validation_Country__c>();
    Map<String, Map<String, Validation_Region__c>> validRegions = new Map<String, Map<String, Validation_Region__c>>();
// ...

   For(Validation_Country__c obj : [Select Id,Country_Name__c,Transportation_Zone__c FROM Validation_Country__c]){
        validCountries.get( obj.Transportation_Zone__c,obj );
        System.debug(validCountries);
              
    }
   
For(Validation_Region__c objR : [Select Id,Country_Key__c,Description__c,Name FROM Validation_Region__c]){

    String countryKey = objR.Country_Key__c;

    Map<String, Validation_Region__c> regionMap = validRegions.get(countryKey);
    // Maybe rework to use Map.containsKey rather than null check. Would be cleaner.
   
    if(regionMap == null) {
        regionMap = new Map<String, Validation_Region__c>();
        validRegions.put(countryKey, regionMap);
    }
    string regionKey = objR.Description__c;
    regionMap.put( regionKey,objR);
    }


For( Sampling__c s : Trigger.new){
    If((s.Country__c != null) && (S.Override__c == 'Yes')){
        String countryKey = s.Country__c;
        String regionKey = s.State_Province__c;
 
       // If(validCountries.containsKey(countryKey) && validRegions.containsKey(countryKey)) {
            // The country appears to be valid and there are possible Region matches
          //  Validation_Country__c vc = validCountries.get(countryKey);
              
            If(validRegions.get(countryKey).containsKey(regionKey)) {
                // The Region belongs to the country
                Validation_Region__c vr = validRegions.get(countryKey).get(regionKey);
             }
   
         }
     }
}
ShaTShaT
HI,

I think in below line you are doing wrong.

validCountries.get( obj.Transportation_Zone__c,obj );
validCountries is a map , to get the value you need to pass only one arrgument i.e key. 

Below are the links that can help you to understand map

http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_collections_maps.htm
http://www.salesforce.com/us/developer/docs/dbcom_apex250/Content/apex_methods_system_map.htm

Thanks
ShaT