You need to sign in to do that
Don't have an account?
Reddy@SFDC
Type casting in apex
Hi,
In apex class ,
webservice Integer UserId;
then i want to insert this value in to SFDC Account field which is text datatype, how can i do this
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
Hi,
In apex class ,
webservice Integer UserId;
then i want to insert this value in to SFDC Account field which is text datatype, how can i do this
You can use the following statement which converts integer to string datatype.
string s = String.valueOf(UserId) ;
Actually my code is as follows....
global class InboundLinxUserRegistration {
global class dtRegistrationInput {
webservice Integer UserId;
webservice String First_Name;
webservice String Last_Name;
webservice String Email_Address;
webservice String Status;
webservice String Workplace_Id;
webservice String Workplace_Name;
webservice String Workplace_Province;
webservice String Workplace_City;
webservice String Workplace_Postal_Code;
webservice String Workplace_Address;
webservice String Speciality;
webservice String Record_Type;
}
global class dtRegistrationOutput {
webservice String status;
webservice String Message_Text;
}
public webservice static dtRegistrationOutput Registration(dtRegistrationInput Registration){
dtRegistrationOutput retvalue=new dtRegistrationOutput();
retvalue.status='Success';
return retvalue;
List<Account> user=[select National_Code__c, FirstName,LastName,PersonEmail,Account_Status_NES__c,Primary_Parent_vod__c,Primary_Province_NES__c,Primary_City_NES__c,Primary_Postal_Code_NES__c,Primary_Address_1_NES__c,Specialty_1_vod__c, RecordtypeId from Account where National_Code__c=:Registration.UserId];
if(user.size()==0) {
retvalue.status='Failur';
retvalue.Message_Text='Record Not Found';
}else {
user[0].National_Code__c=Registration.UserId; // HERE THE ERROR
user[0].FirstName=Registration.First_Name;
user[0].LastName=Registration.Last_Name;
user[0].PersonEmail=Registration.Email_Address;
user[0].Account_Status_NES__c=Registration.Status;
user[0].Primary_Parent_vod__c=Registration.Workplace_Id;
user[0].Primary_Province_NES__c=Registration.Workplace_Province;
user[0].Primary_City_NES__c=Registration.Workplace_City;
user[0].Primary_Postal_Code_NES__c=Registration.Workplace_Postal_Code;
user[0].Primary_Address_1_NES__c=Registration.Workplace_Address;
user[0].Specialty_1_vod__c=Registration.Speciality;
user[0].recordtypeId=Registration.Record_Type;
try{
insert user[0];
} catch (Exception e){
retValue.Status='Failure';
retValue.Message_Text= e.getMessage();
}
}
return retvalue;
}
}
That should work. Is String.valueOf() not working? What is the error if it isn't?
global class dtRegistrationOutput {
webservice String status;
webservice String Message_Text;
}
public webservice static dtRegistrationOutput Registration(dtRegistrationInput Registration){
dtRegistrationOutput retvalue=new dtRegistrationOutput();
retvalue.status='Success';
return retvalue;
List<Account> user=[select National_Code__c, FirstName,LastName,PersonEmail,Account_Status_NES__c,Primary_Parent_vod__c,Primary_Province_NES__c,Primary_City_NES__c,Primary_Postal_Code_NES__c,Primary_Address_1_NES__c,Specialty_1_vod__c, RecordtypeId from Account where National_Code__c=:Registration.UserId];
if(user.size()==0) {
retvalue.status='Failur';
retvalue.Message_Text='Record Not Found';
}else {
user[0].National_Code__c=String.valueOf(Registration.UserId);
user[0].FirstName=Registration.First_Name;
user[0].LastName=Registration.Last_Name;
user[0].PersonEmail=Registration.Email_Address;
user[0].Account_Status_NES__c=Registration.Status;
user[0].Primary_Parent_vod__c=Registration.Workplace_Id;
user[0].Primary_Province_NES__c=Registration.Workplace_Province;
user[0].Primary_City_NES__c=Registration.Workplace_City;
user[0].Primary_Postal_Code_NES__c=Registration.Workplace_Postal_Code;
user[0].Primary_Address_1_NES__c=Registration.Workplace_Address;
user[0].Specialty_1_vod__c=Registration.Speciality;
user[0].recordtypeId=Registration.Record_Type;
try{
insert user[0];
} catch (Exception e){
retValue.Status='Failure';
retValue.Message_Text= e.getMessage();
}
}
return retvalue;
}
}
a
nd the error is
Error: Compile Error: Invalid bind expression type of Integer for column of type String at line 27 column 296