1
Apex_Customer__c objcus=new Apex_Customer__c();
objcus.Name='Test ABC';
insert objcus;//it will creat new customer records
Apex_Invoice__c objnewinvoice=new Apex_Invoice__c();
objnewinvoice.Apex_Status__c='Pending';
objnewinvoice.Apex_Amount_Paid__c=1000;
objnewinvoice.Apex_Customer__c='objcus.id';
insert objnewinvoice;
system.debug('The customer we added is +objcus+ and the corresponding invoices are +objnewinvoice');
2

The variable should not be in quotes, as this makes it a String. When cast back to an Id, it is found to be invalid, thus causing the rrror.

objnewinvoice.Apex_Customer__c=objcus.id;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.