0

error is Error: Compile Error: expecting right square bracket, found 'And' at line 48 column 111

trigger SendEmailUser on Opportunity (after insert,after update) {

    Set<Id> setResource=new Set<Id>();
    Set<Id> setjob=new Set<Id>();
    List<NewJob__c> LatestJob=new List<NewJob__c>();
    for(Opportunity opp:Trigger.new){
        if(opp.Status__c == 'new'){
            if(opp.Resource__c != null ){
                setResource.add(opp.Resource__c);
              //  setjob.add(opp.Job__c);
            }
        }
    }

    List<String> lstEmails=new List<String>();
    if(!setResource.isEmpty()){
        List<Resource__c> lstResource= [Select Id,Email__c from Resource__c Where Id IN : setResource];
        if(!lstResource.isEmpty())
        {
            for(Resource__c res:lstResource)
            {
                lstEmails.add(res.Email__c);
            }
        }
    }
   string ljob='';
     if(!setResource.isEmpty()){
    List<NewJob__c> newJoblist=[SELECT Id FROM NewJob__c order by CreatedDate desc limit 1];


        if(!newJoblist.isEmpty())
        {
             for(NewJob__c jobl:newJoblist){
              setjob.add(jobl.id);
      //          ljob=ljob+'https://ap2.salesforce.com/'+jobl.id+'\n';
           }
       }

   }






    String Body='';
    if(!setResource.isEmpty()){
        List<Job_Application__c> Joblist=[SELECT Id FROM Job_Application__c order by CreatedDate desc limit 1  And Id IN(setjob) ];
        if(!Joblist.isEmpty())
        {
            for(Job_Application__c job:Joblist){
                body=body+'https://ap2.salesforce.com/'+job.id+'\n';
               // body=ljob+'https://ap2.salesforce.com/'+job.id+'\n';
            }
        }
    }

    if(!lstEmails.isEmpty()){
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setToAddresses(lstEmails);   
        mail.setSubject('Job Alert');  
        mail.setPlainTextBody(Body);
        mail.setHtmlBody(Body);
        Messaging.SendEmail(new Messaging.SingleEmailMessage[] {mail});
    }

}
Keith C
  • 135,775
  • 26
  • 201
  • 437
user25465
  • 11
  • 4
  • in opportunity object have status and Opportunity fields and Resource field, in Resource object have id resource name and email filed ,In New job object have New job id, name opportunity (lookup),in job application have id,name,Job(lookup) fields – user25465 Oct 30 '15 at 07:53
  • requirement is when ever new Opportunity is created or updated with status new send mail to the resource mail id with the latest job allocation of latest job of oppurtunity to get url – user25465 Oct 30 '15 at 08:01

1 Answers1

0

In SOQL the terms must be in the correct order and follow the syntax listed in SOQL SELECT Syntax. So to fix the compile error your query should be:

SELECT Id
FROM Job_Application__c
WHERE Id IN :setjob
ORDER BY CreatedDate desc
LIMIT 1
Keith C
  • 135,775
  • 26
  • 201
  • 437