1

I've this class that I need to test it:

    public class A800ExpiredClientReportV2 {
        Public ID quotID {get;set;}
        Public  List<Quotation__c> quotList {set;get;}
        Public  List<Call__c> callList {set;get;}
        public A800ExpiredClientReportV2(){
            quotList = [SELECT ID, To__c, Quotation_Total__c, Time_Left__c, Client_Name__c, Client__c, Name, Phone__c, Confirm_Renewal__c FROM Quotation__c WHERE (Expiry_Notification_1__c = true AND Confirm_Renewal__c = false AND Stored_Inventory_Items__c > 0 AND Paid_Invoices__c >0) OR (Expiry_Notification_1__c = true AND Subsequent_Quotation__c != null AND Paid_Invoices__c >0) ORDER BY To__c];
            callList = [SELECT Call_Date__c, Client_Name__c,Phone__c, Response__c, Quotation__c, Quotation_Name__c, Client__c FROM Call__c ORDER BY Client_Name__c ];
        }
     }

My prototype test class is:

@isTest
private class A800ExpiredClientReportV2Test {

static testMethod void myUnitTest() {
    Client__c randomClient = new Client__c(Name__c = 'MAZEN', Phone__c='0000');
    insert randomClient;

    Quotation__c quotation_tst_1 = new Quotation__c(Client__c = randomClient.Id, Duration_Months__c = 1, Expiry_Notification_1__c = true, Confirm_Renewal__c = false, Stored_Inventory_Items__c = 1, Paid_Invoices__c = 1);
    insert quotation_tst_1;

    Test.startTest();
        A800ExpiredClientReportV2 expiredReport = new A800ExpiredClientReportV2();
    Test.stopTest();

    System.assertEquals(quotation_tst_1, expiredReport.quotList[0]);

I've got an error message that told me:
Field is not writeable: Quotation__c.Expiry_Notification_1__c A800ExpiredClientReportV2Test.cls How can I solve this problem?

  • 4
    is Expiry_Notification_1__c a formula field ? – Ratan Paul Jul 5 '16 at 11:37
  • How can I know if it is? if I can't enter the sandbox yet, I'm working on Force.com IDE . @Ratan – MAZux Jul 5 '16 at 15:04
  • 1
    If you are using Force.com IDE then you will be able to view the orgs schema. In the package explorer on the left side of the window, expand the current Force.com project you are working in and double click the schema that will allow you to browse all of the objects and fields within the org. – cmmoutes13 Jul 5 '16 at 15:36
  • How can I define the formula that the field works on? @cmmoutes13 – MAZux Jul 5 '16 at 15:59
  • It's a formula field, but I don't know the definition of it or how to get it? @Ratan – MAZux Jul 5 '16 at 16:25
0

Non-writeable fields usually are formulas, roll-up summaries or auto-number fields.

For auto-number there isn't much you can do and it doesn't seem to be the case, so I won't talk about them.

For formulas and roll-up summaries, you need to create data so they'll be evaluated correctly.

Ex.: If you have a formula that returns true if the Expiration Date is in the past, you need to create a record with a Expiration Date in the past.

  • How can I know the formula syntax from Force.com IDE? – MAZux Jul 6 '16 at 9:23
  • You need to update the metadata subscription to include the CustomObjects. Then go to src > objects >Quotation__c.object and search for the field name. – Fernando Gavinho Jul 6 '16 at 12:05
0

Formula fields are read only and the value cannot be modified.

Quotation__c quotation_tst_1 = new Quotation__c(Client__c = randomClient.Id, Duration_Months__c = 1, **Expiry_Notification_1__c = true**, Confirm_Renewal__c = false, Stored_Inventory_Items__c = 1, Paid_Invoices__c = 1);
    insert quotation_tst_1;

Being a formula field, you need to remove Expiry_Notification_1__c from insert statement.

Expiry_Notification_1__c field will be automatically populated based on its formula. Check the formula for this field and based on the formula provide values for a record.

  • How can I know the formula syntax from Force.com IDE? – MAZux Jul 6 '16 at 9:24

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.