You need to sign in to do that
Don't have an account?
list index out of bounds 0 error ...plzz help-
here is my code::::::
global class InboundLinxUserRegistration {
global class dtRegistrationInput {
webservice ID UserId;
webservice String First_Name;
webservice String Last_Name;
webservice String Email_Address;
webservice String Status;
webservice ID 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 date mydate;
webservice string added;
webservice String status;
webservice String Message_Text;
}
public webservice static dtRegistrationOutput userregistration(dtRegistrationInput userregistration){
dtRegistrationOutput retvalue=new dtRegistrationOutput();
retvalue.status='Success';
List<Account> acc=[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=:userregistration.UserId];
if(acc.size()==0){
acc[0].National_Code__c=userregistration.UserId;
acc[0].FirstName=userregistration.First_Name;
acc[0].LastName=userregistration.Last_Name;
acc[0].PersonEmail=userregistration.Email_Address;
acc[0].Account_Status_NES__c=userregistration.Status;
acc[0].Primary_Parent_vod__c=userregistration.Workplace_Id;
acc[0].Primary_Province_NES__c=userregistration.Workplace_Province;
acc[0].Primary_City_NES__c=userregistration.Workplace_City;
acc[0].Primary_Postal_Code_NES__c=userregistration.Workplace_Postal_Code;
acc[0].Primary_Address_1_NES__c=userregistration.Workplace_Address;
acc[0].Specialty_1_vod__c=userregistration.Speciality;
acc[0].RecordTypeId=userregistration.Record_Type;
try{
insert acc;
} catch(DMLException e) {
retvalue.status='Failure';
retvalue.mydate=system.today();
retvalue.added='false';
retvalue.Message_Text=e.getMessage();
}catch (Exception e){
retvalue.mydate=system.today();
HttpRequest req=new HttpRequest();
Http http=new Http();
HttpResponse res = http.send(req);
System.debug('STATUS:'+res.getStatus());
System.debug('STATUS_CODE:'+res.getStatusCode());
retvalue.Status='Failure';
retvalue.Message_text=e.getMessage();
}
}else {
retvalue.status='Failure';
retvalue.mydate=system.today();
retvalue.added='false';
}
return retvalue;
}
}
Sorry, but this is double facepalm :-)
You write
this mean that acc list does NOT caontain ANY elements. And if it's true (no elements in list) you try to set fields to... element that does NOT exist.
if acc.size() == 0 then no acc[0] can be used!!!
Mayb you want to write acc.size() != 0 ???
No Actually , i want to search for ...if National_Code__c value should not be duplicate....if exist ant it should throw error
Anyway you try to acces not existing elemetn by doing acc[0] in if(acc.size() == 0) condition.
try this: