Question

I have a trigger that moves the values from one object to another, but am stuck on how to move the values of the lookup fields from one to the other. what is the syntax? If you could show me the Company and the Chair_Rep ones that would be great!

<Lead> newLeadsList= new List<Lead>(); for (integer i=0; i<newContacts.size(); i++) { if (newContacts[i].createlead__c == TRUE && oldContacts[i].createlead__c == FALSE ) { newLeadsList.add(new Lead( firstName = newContacts[i].firstName, lastName = newContacts[i].lastName, ***Company = newContacts[i].account.name,*** Status = 'identified', LeadSource = newContacts[i].leadsource , Product_Interest__c = 'CE', //ContactLink__c = newContacts[i].ID, Title = newContacts[i].title, Email = newContacts[i].email, //***Chair_Rep__c = newContacts[i].Chair_Rep__c*** Phone = newContacts[i].Phone, MobilePhone = newContacts[i].MobilePhone, // Address = newContacts[i].MailingAddress, //Website = newContacts[i].Website, nickname__c = newContacts[i].Nickname__c

Was it helpful?

Solution

Lookup fields should contain references (IDs) on records.

Is 'Company' a standard Lead field in your code?

***Company = newContacts[i].account.name,***

If so, then it's a Text(255) type field, which cannot be used as lookup. If you need to make a lookup on a Contact's account record, then you can create a custom Lookup field on Lead with reference to Account. And then you could try this code (assuming ContactCompany is that custom lookup field :

ContactCompany__c = newContacts[i].AccountId

or

ContactCompany__c = newContacts[i].Account.Id

Chair_Rep__c and newContacts.Chair_Rep__c should be lookup fields on same object. Then this

Chair_Rep__c = newContacts[i].Chair_Rep__c    

or this should work

Chair_Rep__c = newContacts[i].Chair_Rep__r.Id
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top