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
ram @SFDCram @SFDC 

Getting illegal conversion error in Wrapper class

global class sendCred{
        public String userName;
        public String userPassword;
        public sendCred(String userName, String userPassword){
            this.userName = userName;
            this.userPassword = userPassword;
        }
    }
    /*==============================*/
    @RemoteAction global static String sendCredentials() {
                
        try{
        User userRec = [select id, Nextiva_Username__c, Nextiva_Password__c from User where id =: userinfo.getuserid()];
             String userName = String.ValueOf(userRec.Nextiva_Username__c);
             String userPassword = String.ValueOf(userRec.Nextiva_Password__c);
             return new sendCred(userName, userPassword);
        } catch(Exception ex){
            return ex.getMessage();
        }
        
    }
I am using above code but getting "Error: Compile Error: Illegal conversion from SoftPhoneDialController.sendCred to String at line 282 column 14" . Please help me on this
Best Answer chosen by ram @SFDC
Mohan ChanderMohan Chander

Hi Ram,

As per your method signature you are returning String from the method.
 @RemoteAction global static String sendCredentials() 

but in your return statement your returning SendCred object. The error message says you cannot do that.
return new sendCred(userName, userPassword);

Ensure that your method return type and return statement both return the same thing.

 

All Answers

Mohan ChanderMohan Chander

Hi Ram,

As per your method signature you are returning String from the method.
 @RemoteAction global static String sendCredentials() 

but in your return statement your returning SendCred object. The error message says you cannot do that.
return new sendCred(userName, userPassword);

Ensure that your method return type and return statement both return the same thing.

 

This was selected as the best answer
ram @SFDCram @SFDC
Thanks  @Mohan Chander