function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dave The RaveDave The Rave 

DML code to create case record not working

// Create the case record sObject 
Case acct = new Case(type='Sample'                
RecordTypeID='0122o000000tZzcAAE'
origin='Web',
optinemail__c=TRUE,
optinperson__c=TRUE,
webcountry__c='GB',
description='test David ',
websiteorigin__c='service.nl');
// Insert the account by using DML
insert acct;
// Get the new ID on the inserted sObject argument
ID acctID = acct.Id;
// Display this ID in the debug log
System.debug('ID = ' + acctID);
All, I would like to create 1 case record using a DML statement, but I keep getting errors, can you see what is wrong with my code?

Some of the fields are picklist fields and some are boolean, maybe this is the issue.

There is also a standard field 'type' but when I add it too the code, the text is always purple.

Error is line 2 unexpected token 'acct'
 
Naresh AltokkNaresh Altokk
Hi,

You missed "," in few places. 

// Create the case record sObject Case acct = new Case(type='Sample' ,
RecordTypeID='0122o000000tZzcAAE' ,
origin='Web',
optinemail__c=TRUE,
optinperson__c=TRUE,
webcountry__c='GB',
description='test David ',
websiteorigin__c='service.nl');
insert acct;
Id acctID = acct.Id;
System.debug('ID = ' + acctID);

Please Like it if this would leads to problem solves.

Thanks,
Naresh
CharuDuttCharuDutt
Hii Dave The Rave
Try The Below Code

Please Don't Forget To Mark It As best Answer If it Helps
Id RecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Type Your RecordType Name Here To Get Its ID').getRecordTypeId();
// Create the case record sObject 
Case acct = new Case(type='Sample',                
RecordTypeID = RecordTypeId,
origin='Web',
optinemail__c=TRUE,
optinperson__c=TRUE,
webcountry__c='GB',
description='test David ',
websiteorigin__c='service.nl');
// Insert the account by using DML
insert acct;
// Get the new ID on the inserted sObject argument
ID acctID = acct.Id;
// Display this ID in the debug log
System.debug('ID = ' + acctID);
Please Don't Forget To Mark It As best Answer If it Helps
Thank You!