You need to sign in to do that
Don't have an account?
Error: Invalid Data. ???System.StringException: Invalid id??? Help
Error: Invalid Data.
Review all error messages below to correct
your
data.
Apex trigger UpdateSARQ caused an unexpected exception,
contact your administrator: UpdateSARQ: execution of AfterUpdate
caused by: System.StringException: Invalid id: Subject_Area__r.Name:
Trigger.UpdateSARQ: line 14, column 12
My Trigger:
trigger UpdateSARQ on Course_History__c (before insert,before update) {
List<Course_History__c> htoUpdte = new List<Course_History__c>();
Map<Id,String> rTypes = new Map<Id,String>();
Map<Id,Decimal> rTypes2 = new Map<Id,Decimal>();
for(Subject_Area_RQ__c rType :[SELECT Id,Subject_Area__r.Name,GL_Term_Value__c FROM Subject_Area_RQ__c]) {
rTypes.put(rType.Id,rType.Subject_Area__r.Name);
rTypes2.put(rType.Id,rType.GL_Term_Value__c);
}
for(Course_History__c ch: trigger.new)
{
if(rTypes.get('Subject_Area__r.Name')== ch.Subject_Area__c && rTypes2.get('GL_Term_Value__c')== ch.GL_Term_Value__c ){
ch.SARQ__c=rTypes.get('Id');
}
htoUpdte.add(ch);
}
}
Please Help
rTypes.get('Id') is looking for the 2 character key 'Id' when infact the key is a 15 or 18 character id.
A line like this should show you what is in your Map.
System.debug('######This is my rTypes:'+rTypes)
With a map like Map<Id,Decimal> you can only 'get' an Id (which returns the corresponding Decimal). You cannot 'get' the Decimal.
Map<Id,Decimal> myMap = new Map<Id,Decimal>() ;
myMap.put('003000000001NjA', 12.5) ;
correct
Decimal num = myMap.get('003000000001NjA') ;
incorrect
Decimal num = myMap.get( 12.5 ) ;
You need to think about what you are loading into maps, and what to loop through to get your updates.
As this is a 'before' trigger you dont need to save a set of the changed records. Just update the fields and the changes will go forward into the database commit automatically.
All Answers
Thank you for your help Simon...
Can you give me an example of this..
What I am trying to do is update a field in course History actually the Lookup field in course history based off term and Subject Area Name in the Subject Area RQ table...
So if 9.1 and finance is the same in the course history and subject area to update the term field and Subject lookup relationship in Course History...
Thanks
rTypes.get('Id') is looking for the 2 character key 'Id' when infact the key is a 15 or 18 character id.
A line like this should show you what is in your Map.
System.debug('######This is my rTypes:'+rTypes)
With a map like Map<Id,Decimal> you can only 'get' an Id (which returns the corresponding Decimal). You cannot 'get' the Decimal.
Map<Id,Decimal> myMap = new Map<Id,Decimal>() ;
myMap.put('003000000001NjA', 12.5) ;
correct
Decimal num = myMap.get('003000000001NjA') ;
incorrect
Decimal num = myMap.get( 12.5 ) ;
You need to think about what you are loading into maps, and what to loop through to get your updates.
As this is a 'before' trigger you dont need to save a set of the changed records. Just update the fields and the changes will go forward into the database commit automatically.