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
Narinder Singh 1Narinder Singh 1 

Illegal assignment from List<RecordType> to String

I am getting this error on the following code

 
String recordTypeName = [Select Name from RecordType where Id=:theCase.recordTypeId and SObjectType = 'Case' limit 1]];

What am I doing wrong?
 
Best Answer chosen by Narinder Singh 1
PratikPratik (Salesforce Developers) 
Hi Narinder,

Please try this:

String recordTypeName = [Select Name from RecordType where Id=:
theCase.recordTypeId  and SObjectType = 'Case' limit 1][0].name;


Thanks,
Pratik

All Answers

Dushyant SonwarDushyant Sonwar
Hi Narinder,
You are assigning object to string that is why it is giving you an error.
Try this
String recordTypeName =[Select Name from RecordType where Id=:theCase.recordTypeId and SObjectType = 'Case' limit 1].name;
Rahul Sangwan7341Rahul Sangwan7341
RecordType recordTypeName = [Select Name from RecordType where Id=:theCase.recordTypeId and SObjectType = 'Case' limit 1];

String recTypeName= recordTypeName .Name;
Hi try by doing this because you are assigning whole RecordType record in String.

Please mark this as Best Answer if it helps you and let me know if you are still finding any issue in this.
 
PratikPratik (Salesforce Developers) 
Hi Narinder,

Please try this:

String recordTypeName = [Select Name from RecordType where Id=:
theCase.recordTypeId  and SObjectType = 'Case' limit 1][0].name;


Thanks,
Pratik
This was selected as the best answer
PratikPratik (Salesforce Developers) 
Glad it helped!

Thanks,
Pratik
Mr SreeniviasMr Sreenivias
illegal type conversion from integr to string how to solve
 
public class UtraceHttp {
    public String result {set;get;}
    public String ipAddress {set;get;}
    public String statuscode {set;get;}
    public String status {set;get;}
    Public Map<String,String> xmlMap{set;get;}
    public void submit(){
        Http p = new Http();
        HttpRequest req= new HttpRequest();
        req.setEndpoint('https://xml.utrace.de/?query='+ipAddress);
        req.setMethod('Get');
        HttpResponse res= p.send(req);        
        result=res.getBody();
        statusCode= res.getStatusCode();
        status=res.getStatus();
        Dom.Document doc= New Dom.Document();
        doc.load(result);
        DOM.XMLNode root= doc.getRootElement();
        for(DOM.XMLNode Chaild:root.getChildElements()) 
        {
            for(DOM.XMLNode v:chaild.getChildElements())
            {
                xmlMap.put(v.getname(),v.gettext());
            }       
        }
    }   
}