0
public with sharing class emailcomponents{

    public lead ids{set;get;}
    public Decimal score1=20;
    public Decimal customerscore=0;
    public Decimal vendorscore=0;
    public emailcomponents(ApexPages.StandardController controller){
           ids=(Lead)controller.getrecord();
    }
    Public void save(){

       // user u=[select id,name,Email from user where alias='ORaj'];
        List<Lead> le=[select id from Lead where firstname=:ids.FirstName or lastname=:ids.LastName or phone=:ids.phone or Email=:ids.Email];
        if(le.size()>0){
            Set<Id> userid=new Set<Id>();
            for(Lead leads:le){
                userId.add(leads.ownerId);
            }
             List<User> owners=[select id,email from User where Id in:userId];
             List<String> toadd=new List<String>();
             for(User u:owners){
                toadd.add(u.email);
             }
             List < Messaging.SingleEmailMessage > emails = new List < Messaging.SingleEmailMessage > ();
             Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
             mail.setToAddresses(toadd);
             mail.setSubject('Some Subject');
             mail.setHtmlBody('record already Existing');
             emails.add(mail);
             Messaging.sendEmail(emails);
        } else{
            Decimal score=20;
            List<Group> groups=[select id,name from Group where type='Queue'];
            Map<String,Id> queueMap=new Map<String,Id>();
            for(Group g:groups){
                queueMap.put(g.name,g.id);
            }
            if(ids.name!='')
                 score=score+10;
            if(ids.email!='')
                 score=score+10;
            if(ids.Phone!='')
                score=score+10;
            if(ids.FirstName!='')
                score=score+10;
            if(ids.Type__c=='Vendor')
                 ids.ownerId=queueMap.get('Verndor');
            else
                 ids.ownerId=queueMap.get('Customer');

            if(score >50)
                 ids.Type__c='Qualified';
            else
                 ids.status__c='General';
            insert ids;

          }  
    }
    }
1
  • Does solution provided by me is helpful to you? Commented Jun 26, 2016 at 11:37

2 Answers 2

3

It is because, in query you cannot get ownerId in select clause. Replace your query with below code:

List<Lead> le=[select id, ownerId from Lead where firstname=:ids.FirstName or lastname=:ids.LastName or phone=:ids.phone or Email=:ids.Email];

Hope it help you :)

0

Try This :

public lead ids{set;get;}
public Decimal score1=20;
public Decimal customerscore=0;
public Decimal vendorscore=0;
public emailcomponents(ApexPages.StandardController controller){
       ids=(Lead)controller.getrecord();
}
Public void save(){

   // user u=[select id,name,Email from user where alias='ORaj'];
    List<Lead> le=[select id,OwnerId from Lead where firstname=:ids.FirstName or lastname=:ids.LastName or phone=:ids.phone or Email=:ids.Email];
    if(le.size()>0){
        Set<Id> userid=new Set<Id>();
        for(Lead leads:le){
            userId.add(leads.ownerId);
        }
         List<User> owners=[select id,email from User where Id in:userId];
         List<String> toadd=new List<String>();
         for(User u:owners){
            toadd.add(u.email);
         }
         List < Messaging.SingleEmailMessage > emails = new List < Messaging.SingleEmailMessage > ();
         Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
         mail.setToAddresses(toadd);
         mail.setSubject('Some Subject');
         mail.setHtmlBody('record already Existing');
         emails.add(mail);
         Messaging.sendEmail(emails);
    } else{
        Decimal score=20;
        List<Group> groups=[select id,name from Group where type='Queue'];
        Map<String,Id> queueMap=new Map<String,Id>();
        for(Group g:groups){
            queueMap.put(g.name,g.id);
        }
        if(ids.name!='')
             score=score+10;
        if(ids.email!='')
             score=score+10;
        if(ids.Phone!='')
            score=score+10;
        if(ids.FirstName!='')
            score=score+10;
        if(ids.Type__c=='Vendor')
             ids.ownerId=queueMap.get('Verndor');
        else
             ids.ownerId=queueMap.get('Customer');

        if(score >50)
             ids.Type__c='Qualified';
        else
             ids.status__c='General';
        insert ids;

      }  
}
}

Regards,

Ajay

2
  • Rather adding complete code again i think only adding the code where OP has issue and provide some description with that will make your answer more helpful.
    – Mr.Frodo
    Commented Jun 25, 2016 at 7:32
  • Thanks for advise, I will remember for next time. @Bingi You have not Queried "OwnerId" for List<Lead> le That's why error is coming . Commented Jun 25, 2016 at 7:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .