You need to sign in to do that
Don't have an account?

INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]
How to avoide the error in the following code................actually when i am testing this webservice with xmlspy it is giving the error
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;
webservice String error;
}
public webservice static dtRegistrationOutput userregistration(dtRegistrationInput userregistration){
dtRegistrationOutput retvalue=new dtRegistrationOutput();
for(List<Account> account :[select National_Code__c,PersonEmail from Account]){
for(Account acc : account) {
if((acc.National_Code__c==userregistration.UserId)||(acc.PersonEmail==userregistration.Email_Address)){
retvalue.status='Failure';
retvalue.error='Duplicate';
}else {
account[0].National_Code__c=userregistration.UserId;
account[0].FirstName=userregistration.First_Name;
account[0].LastName=userregistration.Last_Name;
account[0].PersonEmail=userregistration.Email_Address;
account[0].Account_Status_NES__c=userregistration.Status;
account[0].Primary_Parent_vod__c=userregistration.Workplace_Id;
account[0].Primary_Province_NES__c=userregistration.Workplace_Province;
account[0].Primary_City_NES__c=userregistration.Workplace_City;
account[0].Primary_Postal_Code_NES__c=userregistration.Workplace_Postal_Code;
account[0].Primary_Address_1_NES__c=userregistration.Workplace_Address;
account[0].Specialty_1_vod__c=userregistration.Speciality;
account[0].RecordTypeId=userregistration.Record_Type;
try{
insert acc;
retvalue.added='True';
retvalue.Message_Text='Registration Successfull';
} /*catch(DMLException e) {
retvalue.mydate=system.today();
retvalue.added='false';
retvalue.Message_Text=e.getMessage();
}*/
catch (Exception e){
retvalue.mydate=system.today();
retvalue.added='false';
retvalue.Message_Text=e.getMessage();
}
}
}
return retvalue;
}
return retvalue;
}
}
In your code acc is an account that is already present in your salesforce instance. You are trying to insert an account ehich is already present. Thats why, It is throwing error.
Try to insert account[0].
still same error
First you initialize an account object then try to insert it
Account ac= new Account();
ac..National_Code__c=userregistration.UserId;
//Add allfields
insert ac;
yeah...i did but now i got different erro as follows.......
<
Message_Text>Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Account: bad field names on insert/update call: LastName, FirstName: [LastName, FirstName]</Message_Text>
There are no standard fields like FirstName, LastName in Account. Use the correct API name if you are using custom fields.
The fields FirstName and LastName are valid if you are using PersonAccounts so if that is what you want, you have to include the recordtypeId defined for your PersonAccounts in the insert statement.