Invalid foreign key relationship when I try to add a new custom object to exsting string

I have a Lead and a custom object called Social Account (API Name = Social_Account__c).

I linked as follows: Lead is the parent of social accounts. therefore, management has many social accounts.

In the social account, I created my own field called Lead (Data Type: Lookup) to make the connection.

and here is the detailed information:

API Name: Lead__c

Regarding Lead

Child Node Name: Social_Accounts

Related List Shortcut: Social Accounts

I would like to add new social accounts to existing links if there is a guide with the same email address.


Social_Account__c social_account = new Social_Account__c();
/*add whatever fields on social_account*/

List<Lead> leads =[select Id from Lead where Email =:emailAddress ];
if(leads.size()>0)
{ 
    Lead existing_lead = new Lead(Id = leads[0].id);
    //ideally i would like to do something like this
    social_account.Lead__c.id = existing_lead.id; //this is where I get an error from

    insert social_account;
    update existing_lead;
}

but I get the following error message:

: : : Social_Account_c.Lead_c

? .

+3
1

" " (.) , .

social_account.Lead__c.id = existing_lead.Id; social_account.Lead__c = existing_lead.Id;

, . Salesforce

SET, : Social_Account__c.Lead__c, , .

GET (), , Social_Account__c.Lead__r.(whatever fields on Lead you want).

"_c" "_r" , , , Opportunity.AccountId , , Opportunity.Account.Name.


- , ;) , ​​ , ( Apex Explorer Eclipse). , , .. Apex.

+5

Source: https://habr.com/ru/post/1766504/


All Articles