You need to sign in to do that
Don't have an account?
Why I am getting Illegal assignment from contact to id?
trigger CreateCase on Account (after insert) { for(Account hw : Trigger.new){ List<Contact> contact = [SELECT Id FROM Contact LIMIT 1]; Case c = new Case(); c.AccountId = hw.Id; c.ContactId = contact[0]; c.Status = 'New'; c.Origin = 'Web'; insert c; } }
Thx
All Answers
Thx
Furthermore, your trigger is performing an insert of a contact for each new account. This means that you may try to issue 200 DML statements if you bulk load Accounts, where you really only need a single DML statement. You really should bulkify your trigger. You can read more about bulkification here: https://developer.salesforce.com/blogs/developer-relations/2015/01/apex-best-practices-15-apex-commandments.html