You need to sign in to do that
Don't have an account?
suneel.patchipulusu@gmail.com
Concatenation through SObject
Scenario: Concatenating four custom fields into one custom field, all fields belongs to the same custom Object called 'Claim__c'
1.Claim_Invoice_Number__c
2.Claim_Invoice_Position__c
3.Claim_Document_Line_Item_Number__c
4. Claim_Line_Item__c these four shoul be concatenate and putting into 'Invoice_Con__c'.I am getting an error in the below mentioned code
Error Message: Illegal assignment from SObject:Claim__c to String
This error message is giving in if{---}
Map<String,Claim__c> clmap = new Map<String,Claim__c>(); for(Claim__c Invclm :[select ID,Claim_Invoice_Number__c,Claim_Invoice_Position__c ,Claim_Document_Line_Item_Number__c,Claim_Line_Item__c from Claim__c ]) { clmap.put(Invclm.Claim_Invoice_Number__c+''+Invclm.Claim_Invoice_Position__c+''+ Invclm.Claim_Document_Line_Item_Number__c +''+ Invclm.Claim_Line_Item__c,Invclm); System.debug('step 6:'+ Invclm.Claim_Invoice_Number__c+''+Invclm.Claim_Invoice_Position__c+''+ Invclm.Claim_Document_Line_Item_Number__c +''+ Invclm.Claim_Line_Item__c); } for(SObject obj: Trigger.new) { Claim__c cl = (Claim__c)obj; if(clmap.containsKey(cl.Claim_Invoice_Number__c+''+cl.Claim_Invoice_Position__c+''+ cl.Claim_Document_Line_Item_Number__c +''+ cl.Claim_Line_Item__c)) { cl.Invoice_Con__c=clmap.get(cl.Claim_Invoice_Number__c+''+cl.Claim_Invoice_Position__c+''+ cl.Claim_Document_Line_Item_Number__c +''+ cl.Claim_Line_Item__c); } }
Thanks in advance
Your issue lies in the following:
The map returns a Claim__c and you are assigning it to a String value (Possibly Id? which is actually a String). I think you are trying to assign the Id of the Claim__c. If so you will add '.Id' to the end.
No, I want to assign a comibation of four values into the Invoice_Con__c
Could I do like this. Is it correct way to getting the concatenation value??
Yep, pretty much, except you can remove the ().
The problem is that clmap is a Map<String,Claim__c>. So your code within the "if"...
gets the value at your specified key, returning a Claim__c object. Then you're assigning that Claim__c to cl.InvoiceCon__c, which I assume is a String field on the Claim__c object. Hence the error.
Maybe what you want to do is this (replace the above lines):
That would assign your concatenated string to the Invoice_Con__c field. If this is the case, are you sure you need a map at all? Maybe you want a set?
If I'm wrong and that Invoice_Con__c field is a lookup to a Claim__c object, then you probably just want the Id of the Claim__c object the map is returning. So do: