Date dt = Date.today().addDays( 7 ); |
2 | Opportunity newOpportunity = new Opportunity(Name = 'shivasoft' , StageName = 'Prospecting' , CloseDate = dt); |
10 | Account accountReference = new Account(MyExtID__c = 'SHIVA1234567' ); |
11 | newOpportunity.Account = accountReference; |
14 | Account parentAccount = new Account(Name = 'Shiva' , MyExtID__c = 'SHIVA1234567' ); |
17 | results = Database.insert( new SObject[] { parentAccount, newOpportunity }); |
Note : parent object should be included before the child object in list otherwise you will get following error :
INVALID_FIELD, Foreign key external ID: SHIVA1234567 not found for field MyExtID__c in entity Account: []
No comments:
Post a Comment