+ Start a Discussion
diydiy 

how do i passed table A id in to table B for this scenario?



  two pageblock table

   table A [no is a auto number of table , its not a orginal id]

   no        name

   1         smith
   2         vijay
   3         vikram

   table B [no is manually enter, it is not saved in Database, it is just refer a contact]

   no        contact

   1          77779
   1          78799
   2          77777
   2          93579


  I want to save table A AND table b in single save. how do i passed table A id in to table B ?

Gaurish Gopal GoelGaurish Gopal Goel

Hi Diya,

 

I could not get what you are trying to ask. Please ellaborate so that I can suggest you something. I am sure I can help you out in this.

 

Thanks & Regards

diydiy



  object 1 - sno(auto number) & name
  object 2 - sno(auto number) , contact & sno(fk of object 1)
 

  two pageblock table


   pageblock table A [no is a auto pageblock number , its not a sno id... using Add row button  i added  3 contacts like smith,vijay,vikram]

   no        name

   1         smith
   2         vijay
   3         vikram

   pageblock table B [no is manually enter, it is not a sno id,here also add button, using add button only i add no and contact ]

   no        contact

   1          77779
   1          78799
   2          77777
   2          93579


  I want to save object 1 AND object 2  in single save. for eg object 1 have 2 objects...like 1 account have 2 contacts

Gaurish Gopal GoelGaurish Gopal Goel

You mean that Field "No." on Contact is the Foreign Key of Account ?

 

If yes then to save contacts you will have to save Account first. You can't save them in a single save.

 

For e.g.:

No.     Accountname

1         Gaurish

2          Diya

 

No.     Contactname

1         abc

1         defg

2          xyz

 

 

Field "No." in the second table actually represents that this contact will be inserted under the account having No. = 1

If no account exists with No.=1 then how you can insert the contact under this account.

 

If I am getting you wrong please correct me and let me understand the scenario properly. Thanks.

diydiy

no is the pageblock auto number

Accountno and contactno is a primary key

accountno is a foreign key of account

 

scenario:

 

1) first i add 3 account - A1,A2,A3 ....(pageblock auto number 1,2 ,3)

2) then add 6 contact ( c1,c2,c3,c4,c5,c6)

 

  1- c1,c2(1 have 2 contact)

  2- c3,c4,c5,c6(2 have 4 contacts)

 

 

Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

Hi Diya,

 

Do you have coded this before and struggling at the point to pass the ID from one table to other?

 

If is it so, can you please provide your code, that will be easier to understand. Because, your requirement is not clear eventhough you have given these explainations before.

 

The logic was really interesting, but can't get you exactly what your requirement is...!

diydiy

hi,

 

    Actually requirement is want to save multiple accounts and contacts in same time

Gaurish Gopal GoelGaurish Gopal Goel

In my earlier post, I mentioned that you can save multiple accounts and contacts at the same time. But if you want to save any contact under an account then how is it possible to save that account and contact at the same time.

 

To save the contact under an account, that account should exist in the database so that the reference id can be given while saving the contact under that account.

 

If you still have some confusions then please let me know.

 

Thanks,

Gaurish Gopal GoelGaurish Gopal Goel

Although there is a way around to meet your requirement.

 

You can insert all the accounts and contacts at the same time. Later on you will have to update those contacts which should be under some account. For this you will have to export the accounts data and then apply vlookup and then upsert the contacts.

This process is a bit difficult.

 

For E.g.:

 

Account acc = new account(name='testacc');

Account acc1 = new account(name='testacc1');

.

.

.

and so on. Add all the accounts in a list.

 

List<Account> acclist = new List<Account>();

acclist.add(acc);

acclist.add(acc1);

...... and so on (you can do all this in a for loop.)

 

Contact con = new Contact (lastname = 'lastcon');

Contact con1 = new Contact (lastname = 'lastcon1');

.

.

.

. and so on. Add all the contacts in a list.

 

List<Contact> conlist = new List<Contact>();

conlist.add(con);

conlist.add(con1);

..... and so on (you can do all this in a for loop.)

 

//Now insert both lists at the same time.

insert acclist;

insert conlist;

 

Now your accounts and contacts have been inserted. If there are some contacts which are under some account. Then export the accounts from salesforce. Create a vLookup in excel with the respective Account ID and upsert the contacts.

 

If this solves your problem, please accept this as a solution and if you like then you can give a Kudos by clicking on star.

 

Thanks,