+ Start a Discussion
VinuVinu 

How to remove only a single value from a group of values in Rich text box?

Hi Everone,

 

Setup: Field Name is(Scheduled Classes)  

             I have created a rich text box to enter a list of class names with comma separator through the trigger.              

             Field Name(Completed Class) 

             I have created another normal text box to enter the completed class list.  

 

Functionality: Defaultly all the classes are listed in the Scheduled classes for each student,Once any of the class was                             entered/Saved as completed from Scheduled class, The completed class name only should remove                                   from the Scheduled Class Rich text field 

 

How can i acheive this? Any help can be greatly appreciated 

                   

 

TheIntegratorTheIntegrator

Hi Vinu,

 

You should be able to use the replace string method on the Scheduled Classes rich text field to find and replace the completed class with an empty string.

 

For example, Scheduled_Classes__c.replace(Completed_Class__c, '');

 

You might need to have some variant to take care of comma's as well, for example

Scheduled_Classes__c.replace(Completed_Class__c+',', '');

or

Scheduled_Classes__c.replace(Completed_Class__c+' ,', '');

VinuVinu

Hi,

As you said, If we replace with the completed class value means,

The remaining scheduled class will be deleted, I just need to show the scheduled classes which is not scheduled so far

 

For example:

These are the default values,

Scheduled class = class 1,class 2, class 3.

Completed class = class 2

 

After completed the class 2, The Result will be look as follows,

Scheduled class = class1, class 3

Completed class = class 2 

 

Thanks

Vinu 

TheIntegratorTheIntegrator

Replace will only replace the matched string

 

so for this case

Scheduled class = class 1,class 2, class 3.

Completed class = class 2

Scheduled_Classes__c.replace(Completed_Class__c+',', '');

 

will get you 

Scheduled class = class1, class 3

VinuVinu

Hi,

I tried in many ways and even followed your replace option method too,

But unfortunately none of the options is working.

 

These following lines doesnt make any actions in the existing behaviour.

Scheduled_Classes__c.replace(Completed_Class__c+',', ''); 

 

Can you ensure about the thing which we discussed earlier again?

 

Thank you

Vinu 

TheIntegratorTheIntegrator

Can you post your code, I am pretty sure replace would work. With the statement I gave, you have to make sure the Scheduled classes entered has class name followed by a comma and Completed class just the class name. This is just an example, you will have to tweak and make it robust to handle other inputs.

VinuVinu

Hi ,

 

Here i posted piece  of code.

 

Code

=====

String[] tobesch;
Set<String> TBS = new Set<String> {};

for(EducationTracker__c edt:[Select id,Name,Contact__c,Current_Phase__c,Education__r.Current_Phase__c,To_Be_Scheduled__c,Classes_Scheduled__c,Classes_Completed__c From EducationTracker__c where Education__c in :eid and Contact__c in:studID]){

edtlist.add(edt);
Map_ET.put(edt.Contact__c,edt);
SFDC_Enrollment__c enr = new SFDC_Enrollment__c();
enr = Map_EN.get(edt.Contact__c);
System.debug('enr:'+enr);
edt.Classes_Scheduled__c = enr.Class__r.Name+';\n';//+enr.Class__r.Start_Date_Time__c;

//** add the tobeschedule field to tobesch variable **//

tobesch = edt.To_Be_Scheduled__c.split(';');
System.debug('TotaL:'+tobesch);
for(integer i=0;i<tobesch.size(); i++) {
if(tobesch[i]!=null) {
TBS.add(tobesch[i]+';\n');
System.debug('Total1:'+TBS);
}
}


TBS.replace(edt.Classes_Scheduled__c+',', '');
System.debug('Total2:'+tobesch);

UET.add(edt);
}
upsert UET;
}

 

Here only i use logic for Remove the string value in TobseSchedule text area.

For example:

These are the default values,

To_Be_Scheduled__c = class 1;,class 2;, class 3.

Classes_Scheduled__c = class 2;

 

After completed the class 2, The Result will be look as follows,

To_Be_Scheduled__c = class1; , class 3;

Classes_Scheduled__c = class 2 ;

 

Thanks

Vinu

 

 

TheIntegratorTheIntegrator

you are splitting by semi-colon ; and replacing by comma, no wonder it doesn't work.

 

just change TBS.replace(edt.Classes_Scheduled__c+',', '');

to

TBS.replace(edt.Classes_Scheduled__c, '');

 

and you will see what I mean

VinuVinu

HI,

 

 i am using   TBS.replace(edt.Classes_Scheduled__c, '');

but  code not saved showing exception. i.e  Method does not exist or incorrect signature: [SET<String>].replace(String, String)

 

 

 

this is correct examples :

These are the default values,

To_Be_Scheduled__c = class 1;class 2; class 3. //comma no need between semi -colen;

Classes_Scheduled__c = class 2;

 

After completed the class 2, The Result will be look as follows,

To_Be_Scheduled__c = class1;  class 3;

Classes_Scheduled__c = class 2 ;

 

Thanks

Vinu

TheIntegratorTheIntegrator

sorry, bit of an oversite, TBS is a set of strings, so what you can do is

 

instead of TBS.replace(edt.Classes_Scheduled__c+',', '');


if(TBS.contains(edt.Classes_Scheduled__c))
TBS.remove(edt.Classes_Scheduled__c);

 

Let me know if this works.

VinuVinu

Hi,

 

i am using  if(TBS.contains(edt.Classes_Scheduled__c))
TBS.remove(edt.Classes_Scheduled__c);

 

this is not working. in debug  Remove the value show like this 

|DEBUG|Total2:{Don't Embarrass Yourself;
, Orientation Webinar;
}

but in EducationTracker standard page does not  remove the value in Tobeschedule field.

 

These are the default values,

To_Be_Scheduled__c = Orientation Webinar;1 Marketing 101;Don't Embarrass Yourself

Classes_Scheduled__c = 1 Marketing 101; 

 

After completed the 1 Marketing 101 The Result will be look as follows,

To_Be_Scheduled__c = Orientation Webinar;Don't Embarrass Yourself

Classes_Scheduled__c =1 Marketing 101 ;

 

Thanks

Vinu

TheIntegratorTheIntegrator

Hi Vinu,

 

I'm now a little lost with what you are trying to do, I'll leave you to figure this out with the confirmation that if you want to remove some text from a rich text field, use replace as I suggested. If you want to remove an item from a set, use remove.

 

Hope that helps.