function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
steve456steve456 

Help with a trigger

I have a small doubt 
 
 
I have two obj Account and Contacts
 
 
Contact has a lookup to Account
 
 
 
I am trying  to insert  records of Accounts and I am able to do it successfully 
 
 
I am trying to insert records of Contact and I am able to do it successfully without the Account field
 
 
If i want to give the Account field in the Contact object what should i do
 
 
----------->I have only the Account names but not their ids . 
 
How can i do this
 
Suresh RaghuramSuresh Raghuram

Mr Steve.

 

Since account is a lookup to the contact it will take only id not the Name. So when you click on the lookup it will show the list of account names to you in the front end but behind the screens it will have Id only.

 

Another thing you are creating a contact even with out an account field populated. If you want to avoid this Make that field required at pagelayout level.

 

And you can create an account even with out a contact since it is detail to the contact not  master(what i mean to say is it is not a mandatory field).I will explain it with an example.

 

you have lookup field Account__c on Contact and you want its id in the code to pass it to some variable then it will look like this.

Open developer console and type this.

 

List<Contact> cnt= new List<Contact>();
cnt =[Select Contact.AccountId from contact limit 1];

system.debug('*******AccountId'+cnt);

 

you will find a line with success click onit once and click on open raw log button. Ctl+f types stars click enter.

then you will find the IDs

 

If this clears your doubt make this as solution. If you have any further quries you are welcome.

 

steve456steve456

Suree i know you solution is genuine if i have IDs.

 

 

I donot have IDs and only names and external ids on both objects .

 

 

It can be done through external ids .How do i need to pass this without the Ids through a SOAP UI call.