function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Chad DavisChad Davis 

Class Error?? Illegal assignment from Schema.SObjectField to String

Hey Guys,  I am getting this error in my simple Apex class: Illegal assignment from Schema.SObjectField to String at line 3 column 1

FYI - Opportunity.Description__c is a Long Rich text field.

____

Global with sharing class Job_Description_Transfer {

string htmlString = opportunity.Description__c;

String RegEx ='(</{0,1}[^>]+>)';
string result= htmlString.replaceAll(RegEx, '');



}

What am i doing wrong?

Thanks for your help!!

chad
Best Answer chosen by Chad Davis
AsitM9AsitM9
string htmlString = string.ValueOf(Item__c.Desc__c);

This will solve your problem..

All Answers

AsitM9AsitM9
string htmlString = string.ValueOf(Item__c.Desc__c);

This will solve your problem..
This was selected as the best answer
Chad DavisChad Davis
Thank you for your help. I am a novice and still trying to grasp Apex.  I have another question for you.

how do i update this trigger below to call on the new string value?
As you can see its mapped to the Opportunity which it doesnt need to me anymore.

________________________________________

Trigger Job_Description_Transfer on Job_Contract__c (before insert,before update) {

//create a set of job descriptions      
  
    set<Id> setRelatedJobIds = new Set <Id>();
    set<Id> setJobSegmentIds = new Set <Id>();
   
    for (Job_Contract__c japp: Trigger.new) {
        if(japp.Related_Job__c!=null)   
            setRelatedJobIds.add(japp.Related_Job__c);
        if(japp.Job_Segment__c!=null)   
            setJobSegmentIds.add(japp.Job_Segment__c);
       
    }
  
    Map<Id, Opportunity> mapOpportunityRecord = New Map<Id, Opportunity>([SELECT Id, Description__c, Job_Timing__c FROM Opportunity WHERE Id IN :setRelatedJobIds]);
    Map<Id, Job_Segment__c> mapSegmentRecord = New Map<Id, Job_Segment__c>([SELECT Id, Segment_Description__c, Segment_Timing__c FROM Job_Segment__c WHERE Id IN :setJobSegmentIds]);
   

   
    if(trigger.isUpdate || trigger.isInsert){ 
  
        for(Job_Contract__c jaTrigger : trigger.new) {
          
            if(jaTrigger.Job_Segment__c!=null){
                jaTrigger.Segment_Description__c = mapSegmentRecord.get(jaTrigger.Job_Segment__c).Segment_Description__c;
                jaTrigger.Related_Segment_timing__c = mapSegmentRecord.get(jaTrigger.Job_Segment__c).Segment_Timing__c;
               
            }
            else{
                jaTrigger.long_text_field__c = mapOpportunityRecord.get(jaTrigger.Related_Job__c).Description__c;
                jaTrigger.Related_Job_Timing__c = mapOpportunityRecord.get(jaTrigger.Related_Job__c).Job_Timing__c;
            }
           
           
        }
       
        }

}