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
vinni1vinni1 

Trigger error

Hi All,

 

Please help me on bellow error

 

Error: Compile Error: Initial term of field expression must be a concrete SObject: List<New__c> at line 17 column 33

 

R_Type__c is picklist filed

 

trigger Updateallcases on Case (after insert) {
 
  List<Case> updatedCases=new List<Case>();
  List<RecordType> recType = [select id from RecordType where name = 'New Rec' AND sobjecttype = 'Case' AND IsActive = TRUE limit 1];
  List<New__c> customSettingMap = New__c.getall().values();
 
  if(!recType.isempty())
  {
   String RecordTypeAid = rectype[0].id;
   for(case c : Trigger.new)
   {
     if(c.RecordTypeId == RecordTypeAid )
     {
          if(c.Comments__c == customSettingMap.External__c)
          {
            c.R_Type__c = customSettingMap.Case_Type__c;
            updatedCases.add(c);
          }
        
     }
 
   }
  }
  Update updatedCases;
}

Mariappan PerumalMariappan Perumal

Hi Vinni

 

I think the Problem here is you got the values of the customsetting .Instead you can get the map of those customsetting .

 

List<New__c> customSettingMap = New__c.getall().values();

 

The above list contains only the values in the New__c custom setting , but it won't know which value is for External__c and Case_Type__c in that list.

 

So You can go with getall() method to access all the key-value pair in the custom setting :

 

Map<String_dataset_name, CustomSettingName__c> mcs = CustomSettingName__c.getAll();

 

Kindly let me incase you need assistance on the above.

 

Thanks

Mariappan Perumal

magicforce9magicforce9

Hi,

 

You have a customSetting(New__c) of List type of which you have extracted all the values in customSettingMap(This is a List) and you are comparing & assiging the values of one field against a list and this isn't possible. Please see the changes  that I've made below. I'm assuming that 

if(c.Comments__c == customSetting.External__c)

 Your custom setting will have only one entry that matches to the above if condition.

 

Below is my code.

 

trigger Updateallcases on Case (after insert) {
 
  List<Case> updatedCases=new List<Case>();
  List<RecordType> recType = [select id from RecordType where name = 'New Rec' AND sobjecttype = 'Case' AND IsActive = TRUE limit 1];
  List<New__c> customSettingMap = New__c.getall().values();
 
  if(!recType.isempty())
  {
   String RecordTypeAid = rectype[0].id;
   for(case c : Trigger.new)
   {
     if(c.RecordTypeId == RecordTypeAid )
     {
          for(New__c customSetting : customSettingMap)
          {
            if(c.Comments__c == customSetting.External__c)
            {
              c.R_Type__c = customSetting.Case_Type__c;
              updatedCases.add(c);
            }
          }
        
     }
 
   }
  }
  Update updatedCases;
}

 

 

vinni1vinni1
Thanks for your reply
getting bellow error
Error: Compile Error: Invalid field R_Type__c for SObject New__c at line 18 column 33
magicforce9magicforce9

Check if the API name of the field R_Type__c on Case object is correct and if the type matches that of Case_Type__c field on your custom settings, if the data type is different may be you need to cast it...Some thing like string.ValueOf(customSetting.Case_Type__c) 

vinni1vinni1

Hi,

Thanks for your help

 

The API Name is given correctly

 

Case_Request_Type__c is Text field and Request_Type__c is Picklist field

 

Error: Compile Error: Invalid field Case_Request_Type__c for SObject JPCCDefaultQueueForNoMatchKeyword__c at line 18 column 48

 

 

trigger Updateallcases on Case (after insert) {
 
  List<Case> updatedCases=new List<Case>();
  List<RecordType> recType = [select id from RecordType where name = 'New Rec' AND sobjecttype = 'Case' AND IsActive = TRUE limit 1];
  List<New__c> customSettingMap = New__c.getall().values();
 
  if(!recType.isempty())
  {
   String RecordTypeAid = rectype[0].id;
   for(case c : Trigger.new)
   {
     if(c.RecordTypeId == RecordTypeAid )
     {
          for(New__c customSetting : customSettingMap)
          {
            if(c.Comments__c == customSetting.External__c)
            {
              c.R_Type__c = string.ValueOf(customSetting.Case_Type__c) 
updatedCases.add(c); } } } } } Update updatedCases; }
vinni1vinni1

HI,

Thanks four help

 

I am getting bellow error after changing my code

 

  Error: Compile Error: Invalid type: String_dataset_name at line 6 column 7

 

trigger Updateallcases on Case (after insert) {

 
  List<Case> updatedCases=new List<Case>();
  List<RecordType> recType = [select id from RecordType where name = 'New Rec' AND sobjecttype = 'Case' AND IsActive = TRUE limit 1];
  //List<New__c> customSettingMap = New__c.getall().values();
  Map<String_dataset_name, New__c> customSettingMap = New__c.getAll();
 
  if(!recType.isempty())
  {
   String RecordTypeAid = rectype[0].id;
   for(case c : Trigger.new)
   {
     if(c.RecordTypeId == RecordTypeAid )
     {
          if(c.Comments__c == customSettingMap.External__c)
          {
            c.R_Type__c = customSettingMap.Case_Type__c;
            updatedCases.add(c);
          }
        
     }
 
   }
  }
  Update updatedCases;
}

Mariappan PerumalMariappan Perumal

Hi 

 

Change the String_dataset_name to just String

 

 Map<String_dataset_name, New__c> customSettingMap = New__c.getAll(); ------>

 

 Map<String, New__c> customSettingMap = New__c.getAll();

 

Try to use and let me know incase it didnt resolve your issue.

 

Thanks

Mariappan Perumal