You need to sign in to do that
Don't have an account?
Dilyan Dimitrov
Apex Account to Contact set email
Hello,
I'm trying to execute the code in the following test class:
Could you please advise what am I doing wrong and how to execute this test class without such error?
Regards,
Dilyan
I'm trying to execute the code in the following test class:
static testMethod void testLeadStatusExistingDeal() { Test.startTest(); Lead record = new Lead(LastName = 'Dimitrov', Company ='emp1', Monthly_Volume__c= '1234', Phone='1423542452', Website='www.google.com'); insert record; System.debug('record ' + record); Contact contact = new Contact(Company_Name__c = record.id, email = 'dylan@dylan.com'); Contact contact1 = new Contact(Company_Name__c = record.id, email = 'dilyan@dilyan.com'); insert contact; insert contact1; Account account = new Account(name = 'acc1'); insert account; Merchant_To_Contact__c merchantToAccount = new Merchant_To_Contact__c(Merchant_Name__c = account.id, email__c = 'dylan@dylan.com'); Merchant_To_Contact__c merchantToAccount1 = new Merchant_To_Contact__c(Merchant_Name__c = account.id, email__c = 'dilyan@dilyan.com'); insert merchantToAccount; insert merchantToAccount1; ApexPages.StandardController c = new ApexPages.StandardController(record); LeadToMerchantController ltmc = new LeadToMerchantController(c); String leadStatusExistingDeal = ltmc.leadStatusExistingDeal(record); System.debug('leadStatusExistingDeal ' + leadStatusExistingDeal); Test.stopTest(); }Instead I get the following error Field is not writeable: Merchant_To_Contact__c.Email__c
Could you please advise what am I doing wrong and how to execute this test class without such error?
Regards,
Dilyan
Is it Read-only?
Or perhaps a Formula field (which you cannot write) - this could make sense as a formula can be used to lookup values in parent objects, so in this case it could be to a field on Account?
Have a look at the field (maybe stick a screen shot of the config if you don't understand it) and you'll see!
Indeed the Email__c field in Merchant_To_Contact__c is a formula field.
It is also a custom, filterable and nilable.
Could you please advise what I need to do next in order to avoid the following error I'd like to ask you to include some code example as well.
Regards,
Dilyan
You can't write the contents of a formula field... it's like trying to "set" the answer to 2+2 to your own value, it's not possible, 2+2 is just 4, it just is.
To remove this error from your code (here is the code example!) you need to not include Email in your merchant_to_contact__c records:
(lines 15 and 16)
Thanks for the advice but I've tried to execute the code without and I got some strange error which I do not know how to solve.
Please have a look at the screenshot of the execution log.
Could you please advise how to avoid such error and run my test method?
Regards,
Dilyan