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
Kathryn BullockKathryn Bullock 

Error message with code

public class DedupeCasesHandler {
    public static void deDupeCases (List<Opportunity> Opps){
Set<String> setUnique            = New Set<String>();
Set<String> setUniqueDataBase    = New Set<String>();
Set<String> Field1               = New Set<String>();
Set<String> Field2               = New Set<String>();
        
        
        For (Opportunity objOpp : Opps){
If(objOpp.Oppty_Type__c !=Null && objOpp.Opport_Acct_SF_ID__c !=Null){
    Field1.add(objOpp.Oppty_Type__c);
	Field2.add(objOpp.Opport_Acct_SF_ID__c);
    
    String strKey = objOpp.Oppty_Type__c+ '_' +objOpp.Oppty_Type__c+ '_' +objOpp.Oppty_Type__c+ '_' +objOpp.Oppty_Type__c;
     if(strKey != null && strKey != '')
setUnique.add(strKey);
    system.debug('setUnique' +setUnique);
    }
}
if(!setUnique.isEmpty()){
	system.debug('Im here');
    For (Opportunity objOpp : [SELECT Id,Field1,Field2]){
String strKeyDataBase = objOpp.Oppty_Type__c+ '_' +objOpp.Opport_Acct_SF_ID__c;
        setUniqueDataBase.add(strKeyDataBase);
system.debug('setUniqueDataBase'+setUniqueDataBase);
        }
    }
        For(Opportunity objOpp : Opps){
 IF(objOpp.Oppty_Type__c !=Null && objOpp.Oppty_Type__c !=Null && objOpp.Oppty_Type__c != Null && objOpp.Oppty_Type__c !=Null){
     String strKey = objOpp.Oppty_Type__c+ '_' +objOpp.Opport_Acct_SF_ID__c;
     if(!setUniqueDataBase.isEmpty() && setUniqueDataBase.contains(strKey)){
objOpp.addError('Duplicate Opportunity Found Contact the Salesforce Administrator');
         }
     }
          }
}
}

This code states that there is an error at line 22.  The problem is: Expecting 'FROM' but was: ']'

Is it possible someone could explain this error to me and let me know if this code is good to go?
Best Answer chosen by Kathryn Bullock
Gustavo BertolinoGustavo Bertolino
You should specify where you taking the fields from adding FROM in your query, that is, from which sObject you're selecting the fields you want to select, otherwise you query won't work and the error message will be thrown

All Answers

Gustavo BertolinoGustavo Bertolino
You should specify where you taking the fields from adding FROM in your query, that is, from which sObject you're selecting the fields you want to select, otherwise you query won't work and the error message will be thrown
This was selected as the best answer
Gustavo BertolinoGustavo Bertolino
In your case, your query in line 22 should be something like this: [SELECT Id, Field1 ... FROM Opportunity]. I also recommend that you use the keyword WHERE and specify what kind of Accounts you want to grasp in your query.
Kathryn BullockKathryn Bullock
For (Opportunity objOpp : Opportunities){
IF(objOpp.Owner.ProfileID == 'System Administrator')
    trigger NoTwoOpps on Opportunity (before insert) {
        if(Trigger.isBefore && Trigger.isInsert){
            DedupeCasesHandler.deDupeCases
        }
    }}


That fixed it!  Thank you!  I have one more quick question on the trigger as well, it states that there is an unexpected 'For' in the first line?

 

Gustavo BertolinoGustavo Bertolino
It's because your for keyword's first letter was written with upper case. Rewrite the for and if in line 1 and 2 respectively to lower case. Always write keywords using lower case.
Kathryn BullockKathryn Bullock
Thank you!  I am very slowly learning how to do this so I apologize for all of the questions.  I am still recieving the same error message though.