You need to sign in to do that
Don't have an account?
Carly Probasco 14
Illegal assignment from Set<String> to String
I'm trying to return either a string of text or a date field to display on a visualforce page. When i compile it i get the error above. If i take out RatingRelease = new Set<String>(); i get an error System.NullPointerException: Attempt to de-reference a null object. I'm not sure if i have initialized RatingRelease properly.
public String RatingRelease {get;set;} //Returns the Rating Release date or the 'rating pending' RatingRelease = new Set<String>(); IF (Today < currentQRpCase.Rating_Externally_Visible_Date__c){ RatingRelease = 'Rating Pending'; } else IF(Today > currentQRpCase.Rating_Externally_Visible_Date__c){ RatingRelease = currentQRpCase.Rating_Externally_Visible_Date__c.format(); } else { RatingRelease = ''; }
----------------------
public Set<String> RatingRelease {get;set;} ==> Modified Line
02
03//Returns the Rating Release date or the 'rating pending'
04 RatingRelease = new Set<String>();
05
06 IF (Today < currentQRpCase.Rating_Externally_Visible_Date__c){
07 RatingRelease.add('Rating Pending'); ==> Modified Line
08 } else IF(Today > currentQRpCase.Rating_Externally_Visible_Date__c){
09 RatingRelease.add(currentQRpCase.Rating_Externally_Visible_Date__c.format()); ==> ModifiedLine
10 } else {
11 RatingRelease.add(''); ==> Modified Line
12 }
If you are declaring set then you have to use set.add();
Second code:
----------------------------
public String RatingRelease {get;set;} ==> Modified Line
02
03 //Returns the Rating Release date or the rating pending
04 IF (Today < currentQRpCase.Rating_Externally_Visible_Date__c){
05 RatingRelease = 'Rating Pending';
06 } else IF(Today > currentQRpCase.Rating_Externally_Visible_Date__c){
07 RatingRelease = currentQRpCase.Rating_Externally_Visible_Date__c.format();
08 } else {
09 RatingRelease = '';
10 }
Now it won't need Set because RatingRelease is a String.
Best use: In your case, you don't need Set because you are using the if-else condition to assign the variable after execution you'll get only one string. So to store that you only need String.
I hope this helps.
Thanks,
All Answers
RatingRelease = new Set<String>(); --> Here you are assigning the set. So please change this line
public String RatingRelease {get;set;} --> public Set<String> RatingRelease{get; set;}
----------------------
public Set<String> RatingRelease {get;set;} ==> Modified Line
02
03//Returns the Rating Release date or the 'rating pending'
04 RatingRelease = new Set<String>();
05
06 IF (Today < currentQRpCase.Rating_Externally_Visible_Date__c){
07 RatingRelease.add('Rating Pending'); ==> Modified Line
08 } else IF(Today > currentQRpCase.Rating_Externally_Visible_Date__c){
09 RatingRelease.add(currentQRpCase.Rating_Externally_Visible_Date__c.format()); ==> ModifiedLine
10 } else {
11 RatingRelease.add(''); ==> Modified Line
12 }
If you are declaring set then you have to use set.add();
Second code:
----------------------------
public String RatingRelease {get;set;} ==> Modified Line
02
03 //Returns the Rating Release date or the rating pending
04 IF (Today < currentQRpCase.Rating_Externally_Visible_Date__c){
05 RatingRelease = 'Rating Pending';
06 } else IF(Today > currentQRpCase.Rating_Externally_Visible_Date__c){
07 RatingRelease = currentQRpCase.Rating_Externally_Visible_Date__c.format();
08 } else {
09 RatingRelease = '';
10 }
Now it won't need Set because RatingRelease is a String.
Best use: In your case, you don't need Set because you are using the if-else condition to assign the variable after execution you'll get only one string. So to store that you only need String.
I hope this helps.
Thanks,