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
kavya mareedukavya mareedu 

I have an app called "Chemical Equipment" and two custom objects customer and invoices. I want to write a trigger on customer object, when ever the customer status in the customer object is active a invoice should be generated. Here is the code:

public class Cus_Inv_Exmp1 {
    public static void callMe(List<APEX_Customer__c> customers )
    {  
        List<APEX_Invoice__c> InvoiceList=new List<APEX_Invoice__c>();
        for(APEX_Customer__c objCust:customers)
        {   
            if(objCust.APEX_Customer_Status__c=='Active')
            {
                APEX_Invoice__c objInvoice=new APEX_Invoice__c();
                objInvoice.APEX_Status__c='Active';
                objInvoice.APEX_Description__c='Recored created through trigger';
                objInvoice.APEX_Customer__c=objCust.id;
                InvoiceList.add(objInvoice);
                
            }
            
        }
      Insert  InvoiceList;//DML
    }
}


Callout for Trigger :

trigger Cus_Inv_Exmp1 on APEX_Customer__c (after update)
{

     Cus_Inv_Exmp1.callMe(Trigger.new);   
}
Best Answer chosen by kavya mareedu
Lokesh KumarLokesh Kumar
The error is in this line 
objInvoice.APEX_Status__c='Active';

Please check do you have the picklist value added on this field APEX_Status__c

All Answers

kavya mareedukavya mareedu
My Question is I am not able to execute the code. Could you please check where I am going wrong folks!!!!!! Thanks 
Lokesh KumarLokesh Kumar
can you confirm that the status of the customer record is getting updated to "Active"? You can add the debug statement also.
kavya mareedukavya mareedu
Here is my error code when I am trying to update the record to "Active": CHECK!!!!!!!

 
Lokesh KumarLokesh Kumar
The error is in this line 
objInvoice.APEX_Status__c='Active';

Please check do you have the picklist value added on this field APEX_Status__c
This was selected as the best answer
kavya mareedukavya mareedu
Hey! I am not even able to Update to active also, it directly throws an error.
Lokesh KumarLokesh Kumar
Go to your Invoice object and check on this field APEX_Status__c do you have the picklist value 'Active'. Please check the spelling too.
kavya mareedukavya mareedu
You are correct, I don't have that picklist value. I changed it and it worked. How did you figured it out??? From the error message?? If you have figured from error message then how should I do that?? Please guide me!!!!! Thanks a lot :)
Lokesh KumarLokesh Kumar
Cool!
If you see in the error message it clearly says that the bad value for the picklist, which means either the picklist value is missing or a spelling mistake. 
Happy to help!