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
Sabrina Oliveira 3Sabrina Oliveira 3 

Why am I receiving "Variable dos not exist" error?

Hi! I'm calling this class in a process builder. When the "Form" record reaches the approved status, an "Opportunity" is automatically created in the "Account". The question is: I need to automatically fill the Opportunity "Fee__c" field with the same value filled in the "Form". However, I am getting the error "Variable does not exist" on line 18 when I try to assign the value. The field exists and I cannot understand why I am getting this error. What am I missing?

public class Step1 {
    @invocablemethod(label='Step I')
    public static void CreateOpportunity(List<Id> recordId){
        List<Account> accs                         = new List<Account>();
        List<Opportunity> opps                      = new List<Opportunity>();  
        Form__c[] kycs = [Select ID, Fee__c FROM Form__c WHERE Contact__r.AccountId = :recordId ORDER BY LastModifiedDate DESC LIMIT 1];

        Map<Id, OpportunityData> listAccounts     = Opportunities(recordId);                
                 
        for(id item : listAccounts.keyset()){
            OpportunityData oppData = listAccounts.get(item);
            if(oppData.create){
                accs.add(new Account(Id = item, Step_I__c = true));
                opps.add(new Opportunity(Name        = oppData.accountName, 
                                         AccountId = item, 
                                         StageName = 'Qualification',
                                         CloseDate = date.today().addMonths(12),
                                         Fee__c = kycs.Fee__c));
            }
            else
                accs.add(new Account(Id = item, Step_I__c = false));
        }   
        update accs;
        insert opps;        
    }  
Best Answer chosen by Sabrina Oliveira 3
AbhinavAbhinav (Salesforce Developers) 
Hi Sabrina,

Please try

Fee__c = kycs[0].Fee__c

If it helps mark it as best answer

Thanks!

All Answers

AbhinavAbhinav (Salesforce Developers) 
Hi Sabrina,

Please try

Fee__c = kycs[0].Fee__c

If it helps mark it as best answer

Thanks!
This was selected as the best answer
Sabrina Oliveira 3Sabrina Oliveira 3
Thank you, Abhinav! It helped me a lot