You need to sign in to do that
Don't have an account?
Sabrina 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;
}
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;
}
Please try
Fee__c = kycs[0].Fee__c
If it helps mark it as best answer
Thanks!
All Answers
Please try
Fee__c = kycs[0].Fee__c
If it helps mark it as best answer
Thanks!