2

This Error is getting at line 63

global class Integration {

 global class AllObjects {

     webservice string aName;
     webservice string aNum;

     webservice string cName
 }

 global class Return {
     webservice string raName;
 }


webservice static List<Return> Allobjectsmethod(List<AllObjects> a1List) {

 List<Account> accounts = new List<Account>();
 List<Contact> contacts = new List<Contact>();
 List<Return> returns = new List<Return);
 for(AllObjects a1 : a1List)
 {
     Account a = new Account();
     a.Name = a1.aName;
     a.Number = a1.aNum;
     accounts.add(a);
     Contact c = new Contact();
     c.Name = a1.cName;
     contacts.add(c);
     Return r = new Return();
     r.raName = a.Name;
     results.add(r);
 }

 // Bulk insert accounts
 insert accounts;

 // Assign contacts to accounts
 **for(Integer rowIdx = 0; rowIdx < accounts.size(); rowIdx++)** // error occur point
     contacts[rowIdx].AccountId = accounts[rowIdx].Id;      

 // Bulk insert contacts
 insert contacts;

 return returns;
}
1
  • This code doesn't look right. You can't set the Name field for Contact, for example; you have to set FirstName and LastName separately. I think when you typed this into the question you changed it or left something out. Please show us your actual code. Commented Dec 10, 2013 at 15:26

1 Answer 1

1
r.raName = a.Name;

I suspect this should be:

r.raName = a1.Name;  // you were doing for(AllObjects a1 : a1List)

Try it and see if it doesn't fix your problem.

EDIT

I just saw something else that catches my eye that you'll also want to look at. < accounts.size(). I believe this should be < account.size() not accounts.

3
  • i tried your solution but my probelm is not solves it showing an error Variable does not exist. actually my name is storing at a.Name only. Can you give me any suggestions.
    – Sathya
    Commented Dec 10, 2013 at 15:11
  • I suggest you use system.debug('rraName =' + r.raName + ' aName = ' + a.Name'); after each item in your list. But I just saw something else that catches my eye that you'll also want to look at. < accounts.size(). I believe this should be < account.size() not accounts.
    – crmprogdev
    Commented Dec 10, 2013 at 15:32
  • thanq for reply me i solve my problem
    – Sathya
    Commented Dec 10, 2013 at 15:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .