You need to sign in to do that
Don't have an account?
Ryan Greene
Set a number then add 1 to it
Hello,
I am having difficulty adding a number to a set, then once it is set how do I add 1 to that number?
Code below; I receive error on line 3 of: void add(Decimal) from the type Set<Integer>
and error on line 11 of: void valueOf(Set<Integer>) from the type assign, which is directly related to line 3 not being set
I am having difficulty adding a number to a set, then once it is set how do I add 1 to that number?
Code below; I receive error on line 3 of: void add(Decimal) from the type Set<Integer>
and error on line 11 of: void valueOf(Set<Integer>) from the type assign, which is directly related to line 3 not being set
Set<Integer> assignid = new Set<Integer>(); for(Lead lead : [SELECT AssignIDDateTime__c, Assignment_ID__c FROM Lead WHERE AssignIDDateTime__c != null ORDER BY AssignIDDateTime__c DESC LIMIT 1]){ assignid.add(lead.Assignment_ID__c); } for(Lead l : Trigger.new){ if(l.Status == 'Underwriting'){ if(l.AssignIDDateTime__c == null){ l.Assignment_ID__c = decimal.valueOf(1); }else{ l.Assignment_ID__c = decimal.valueOf(assignid) + decimal.valueOf(1); } } }Thank you!
thank you
if this helps to solve your problem please choose this as the best answer !
if(lead.Assignment_ID__c != null)
assignid.add(Integer.valueOf(lead.Assignment_ID__c));
Please choose this as the best answer if it solves the problem! :)
Any thoughts on adding 1 to the value? Now the error just lies on line 11. The error I get now is Illegal assignment from Set to Decimal
To clarify:
Assignment_ID__c is a number field, so Apex seems to take it as a Decimal
when I add that field to the Set<Integer> it gets converted to an Integer
So on line 11 do I need to convert back to a decimal, and then add 1?
I tried a few different things like integer.valueOf(assignId) and decimal.valueOf(assignId). Continue to receive erros :(
How can I convert it back to decimal?
The SOQL finds the last record that was numbered and adds 1 to it, therefore going in order 1 2 3 (I'll add a statement later that if the previous assignid = 3 then make the next one 1).
Now that Im writing this out, do I really need a Set? I guess I would, right?
Heres an updated code. No error on page but I get an error when a record moves to the "Underwriting" stage, something like it needs a decimal, but it's returning an Integer. So, if we can figure out how to convert back to decimal.......
So I tried the counter, thank you for creating it. I'm receiving the same error with the counter as I was before. "System.TypeException: Invalid integer: common.apex.runtime.impl.SetValue@2:" It seems to know the value is 2 where it says "SetValue@2" but again this field is set as decimal, so does this need to be converted to a decimal? How? I think if it gets converted back correctly it will work! Almost there!