You need to sign in to do that
Don't have an account?
AnnaT
Can't get Map data
When I update data, the following trigger can't get "Item_No_seq__c" value.
Please tell me what is a problem...
trigger IchthysRFT on RFT_Category__c (before insert, before update) { Map<String,Map<Double,RFT_Category__c>> rft = new Map<String,Map<Double,RFT_Category__c>>(); Set<String> objNos = new Set<String>(); Set<Double> itemSeq = new Set<Double>(); for(RFT_Category__c record:trigger.new) { objNos.add(record.Object_No__c); itemSeq.add(record.Item_No_seq__c); } for(RFT_Category__c record:[SELECT Id, Item_No_seq__c, Object_No__c FROM RFT_Category__c WHERE Object_No__c IN :objNos AND Item_No_seq__c!=null ORDER BY Item_No_seq__c DESC limit 1]) { if(!rft.containsKey(record.Object_No__c)) { rft.put(record.Object_No__c,new Map<Double,RFT_Category__c>()); } rft.get(record.Object_No__c).put(record.Item_No_seq__c,record); } for(RFT_Category__c record:Trigger.new) { if(rft.containsKey(record.Object_No__c)&& rft.get(record.Object_No__c).containsKey(record.Item_No_seq__c)) { RFT_Category__c tmp = rft.get(record.Object_No__c).get(record.Item_No_seq__c); if(Trigger.isUpdate){ RFT_Category__c oldpd=Trigger.oldMap.get(record.id); if(record.Object_No__c!= oldpd.Object_No__c){ record.Item_No_seq__c = tmp.Item_No_seq__c +1; } } }else { record.Item_No_seq__c = 1; } } }
Thank you,
Anna
Hi,
I see the reason for the same is your query :-
SELECT Id, Item_No_seq__c, Object_No__c
FROM RFT_Category__c
WHERE Object_No__c IN :objNos AND Item_No_seq__c!=null
ORDER BY Item_No_seq__c DESC limit 1
As you are doing limit 1,I won't expecty it to update for bulk records.
All Answers
Can you be more clear,which line is not getting the value.
Dear Vinit_Kumar
Thank you for your reply.
My trigger jumps the following code.
Object_No__c is not null but Item_No_seq__c is always null.
So I modified the last sentence in the following code.
Then I could update single data, but when in bulk mode, this trigger doesn't work properly.
Thank you,
Anna Tanaka
Hi,
I see the reason for the same is your query :-
SELECT Id, Item_No_seq__c, Object_No__c
FROM RFT_Category__c
WHERE Object_No__c IN :objNos AND Item_No_seq__c!=null
ORDER BY Item_No_seq__c DESC limit 1
As you are doing limit 1,I won't expecty it to update for bulk records.
Thank you for your support!
As I'd like to get max Item_No_seq__c value, I used "limit 1".
Is it impossible to get max value in bulk mode?
Not sure what you mean.