You need to sign in to do that
Don't have an account?
FIELD_INTEGRITY_EXCEPTION, Opportunity: id value of incorrect type
I am attempting to update a custom field in both CampaignMember and in Contact. I have checked and rechecked, and the fields are identical, i.e. both are lookups related to opportunity - one with a child relationship to contact, the other with a child relationship to CampaignMember.
However, I am getting the "FIELD_INTEGRITY_EXCEPTION, Opportunity: id value of incorrect type" only on the "update changeContact"
and it appears to me that it should be the same type as the "update changeCampaignMember"
What am I missing? Code follows:
if (myLead.IsConverted == true && myLead.IsConverted != oldLead.IsConverted) {
CampaignMember[] convertedCampaignMember = [SELECT CampaignMember.Id, CampaignMember.Opportunity__c FROM CampaignMember WHERE CampaignMember.Id = :myLead.ConvertedContactId LIMIT 1];
for (CampaignMember changeCampaignMember : convertedCampaignMember){ changeCampaignMember.Opportunity__c = myLead.ConvertedContactId;
update changeCampaignMember; }
Contact[] convertedContact = [SELECT Contact.Id, Contact.Opportunity__c FROM Contact WHERE Contact.Id = :myLead.ConvertedContactId LIMIT 1];
// if (!convertedContact.isEmpty()){
for (Contact changeContact : convertedContact){
changeContact.Opportunity__c = myLead.ConvertedContactId;
update changeContact; }
// } }
If its a lookup to opportunity, then you can not pass in a contact Id for its value (myLead.convertedContactId)
All Answers
This line looks suspect
changeContact.Opportunity__c = myLead.ConvertedContactId;
If Opportunity__c is a lookup to opportunity, then you need to set it to an opportunityId, not a contactId.
I don't think I have that incorrect. In both cases, the "Custom Field Definition Detail" has "Related to Opportunity" for the Lookup options. The Child Relationship Name is what's different. One is Contacts, the other is CampaignMember. CampaignMember appears to be OK. Contacts does not.
Or do I really have them both set up incorrectly?
If its a lookup to opportunity, then you can not pass in a contact Id for its value (myLead.convertedContactId)
yup - you are absolutely right - i had them BOTH wrong