• hybin joseph 2
  • NEWBIE
  • 70 Points
  • Member since 2016

  • Chatter
    Feed
  • 1
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 17
    Replies
Hi there

I am setting up a formula whereby when a certain field is changed (picklist field), the date & time of the last change is returned. My question is how to best capture all the picklist values? 

Should  I use ISPICKVAL/TEXT/CASE? Also, is ISCHANGED necessary here?

AND

ISCHANGED(D2L_Status__c)
CASE(D2L_Status__c,'Draft','Draft – Queried Supplier','Draft – Under Investigation','Input','Input – Queried Supplier','Input – Under Investigation','Pending Live Registration','Pending Live – Queried Supplier','Live','Rejected by Supplier','Rejected by Supplier – Queried Supplier','Rejection – 2nd Request','Rejection – 3rd Request','Transfer Re-application Requested','Objection Reason Request Sent','Objection – Awaiting LOA','Objection Actioned','LOA Obtained - Objection Reason Request Sent','Objection – Awaiting AM/Customer Action','Objection - Awaiting AM/Customer Feedback','Objection – 2nd Request','Objection – 3rd Request','Re-applied for Objection','Objection Complete','Objection Upheld - CLPW'


TIA
 
I need help with making 2 custom fields created to be required if the Do not create Opp checkbox is not checked. If it is checked then the 2 fields shud be required. I also need to map the value of these fields to 2 custom fields in Opportunity. Code from Class below : 
 
public with sharing class ConvertLeadExtn
{
    Final Lead curLead;
    public boolean IsSendEmailChecked{get;set;}
    public String SelectedAccType{get;set;}
    public Contact ContactAcctToRefer{get;set;}
    public boolean IsOppChecked{get;set;}
    public String SelectedConvrtdStatus{get;set;}
    
    //Returns the list of account types
    public list<selectOption> lstAccountType
    {
        get
        {
            List<selectOption> lstAcctType = new List<selectOption>();
            lstAcctType.add(new selectOption('','--None--'));
            lstAcctType.add(new selectOption('Create New Account','Create New Account'));
            lstAcctType.add(new selectOption('Attach to Existing','Attach to Existing'));
            return lstAcctType;
        }
        set;
    }
    
    // Returns the converted Status list
    public List<selectOption> lstConvertedStatusList
    {
        get
        {
            List<selectOption> lstConvertedStatus = new List<selectOption>();
            LeadStatus leadStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];
            lstConvertedStatus.add(new selectOption(leadStatus.MasterLabel,leadStatus.MasterLabel));
            return lstConvertedStatus;
        }
        set;
    }
     
    //Controller
    public ConvertLeadExtn(ApexPages.StandardController controller)
    {
        this.curLead = (Lead)controller.getRecord();
        if(curLead.Id!=null)
        {
            ContactAcctToRefer = new Contact();
        }
    }
           
    //Converts the Lead
    public PageReference ConvertLead()
    {
        Id accountId;
        PageReference accPage;
        try
        {
            Database.LeadConvert leadCnvrt = new database.LeadConvert();
            if(SelectedAccType == null || SelectedAccType =='')
            {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Select Account Type!'));
                return null;
            }
            
            //Sets all the fields that are required
            leadCnvrt.setLeadId(curLead.Id);
            leadCnvrt.setOwnerId(curLead.OwnerId);
            leadCnvrt.setSendNotificationEmail(IsSendEmailChecked);            
            leadCnvrt.setDoNotCreateOpportunity(IsOppChecked);
            leadCnvrt.setConvertedStatus(SelectedConvrtdStatus);
           
            if(SelectedAccType == 'Attach to Existing')
            {
                if(ContactAcctToRefer.accountId !=null)
                {
                    leadCnvrt.setAccountId(ContactAcctToRefer.accountId);
                }
                else
                {
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Select Existing account to attach!'));
                    return null;
                }
            }
            
            if(!leadCnvrt.isDoNotCreateOpportunity())
            {
                leadCnvrt.setOpportunityName(curLead.Company);
            }
            
            Database.LeadConvertResult leadCnvrtResult = Database.convertLead(leadCnvrt);
            accountId=leadCnvrtResult.getAccountId();
            System.assert(leadCnvrtResult.isSuccess());
        }
        catch(exception excptn)
        {
            String excptnMsg = excptn.getMessage();
                     
            if(excptnMsg.contains('CANNOT_UPDATE_CONVERTED_LEAD') || excptnMsg.contains('INVALID_CROSS_REFERENCE_KEY'))
            {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Lead Conversion Failed! Lead is already converted!'));
            }
            else if(excptnMsg.contains('TRANSFER_REQUIRES_READ'))
            {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Opportunity can not be created, User do not have Read Permission!'));
            }
            else
            {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,excptn.getMessage()));
            }
        }
        if(accountId!=null)
        {
            accPage = new pageReference('/'+accountId);
        }
        return accPage;
    }
}

 
I am getting the following error :
Error: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CreateActivityOnLeadConverted: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.CreateActivityOnLeadConverted: line 34, column 1: [] Class.leadconvert.BulkLeadConvert.handleOpportunityInserts: line 740, column 1 Class.leadconvert.BulkLeadConvert.convertLead: line 104, column 1

Below is the trigger I think is the problem but not sure Please help.
 
trigger CreateActivityOnLeadConverted on Opportunity (after insert) {
    
    List<Task> tasksToInsert = new List<Task>();
    List<User> usersToUpdate = new List<User>();
    List<Lead_Quota_Audit__c> lstNewAudits = new List<Lead_Quota_Audit__c>();
    
    Id wholsaleID = null;
    List <RecordType> wId = [Select Id From RecordType where sobjecttype = 'Opportunity' and name = 'Wholesale' limit 1];
    if ((wId != null) && (wId.size() == 1)) wholsaleID = wId[0].Id;
    
    Set<Id> userIds = new Set<Id>();
    for(Opportunity opp : Trigger.new){
        userIds.add(opp.OwnerId);
    }
    
    Map<Id, User> usersById = new Map<Id, User>([SELECT Id, Name, Leads_Assigned_Current_Month__c, Leads_Assigned_Current_Week__c FROM User  WHERE Id IN :userIds]);
    
    for(Opportunity opp : Trigger.new){
        if (opp.RecordTypeId != wholsaleID) {    
            if (opp.ConvertedLeadID__c != null) {
                Task task = new Task(
                    Type = 'Call',
                    Subject = 'Lead Status Changed to Converted',
                    ActivityDate = Date.Today(),
                    WhatId = opp.Id,
                    OwnerId = UserInfo.getUserId(),
                    Status = 'Completed', 
                    Call_Screener_Transfered__c = opp.CS_Transferred__c 
                );
                tasksToInsert.add(task);
                if(opp.Lead_Status__c == 'Open'){
                    User u = usersById.get(opp.OwnerId);
                    if(u != null){
                        u.Leads_Assigned_Current_Month__c++;
                        u.Leads_Assigned_Current_Week__c++;
                        usersToUpdate.add(u);
                        Lead_Quota_Audit__c audit = new Lead_Quota_Audit__c(
                            Lead__c = opp.ConvertedLeadID__c,
                            User__c = u.Id,
                            Old_Owner__c = u.Name
                        );
                        lstNewAudits.add(audit);
                        
                    }
                }
            }
        }
    }
    
    insert tasksToInsert;
    update usersToUpdate;
    if(lstNewAudits.size() > 0) {
        insert lstNewAudits;
    }

}

 
The error I am getting is  :

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger hybinjoseph1.AcctTrigger caused an unexpected exception, contact your administrator: hybinjoseph1.AcctTrigger: execution of AfterInsert caused by: System.FinalException: Cannot modify a collection while it is being iterated.: Trigger.hybinjoseph1.AcctTrigger: line 9, column 1

and my tirgger is :

trigger AcctTrigger on Account (After Insert) {

list<contact> conlist = new list<contact>();

for(Account a : trigger.new){

conlist = [SELECT AccountID, Name from Contact WHERE Mailingcity = :a.Billingcity];

for(contact con : conlist){
con.AccountId = a.Id;
conlist.add(con);

}


}
update conlist;

}



I am new to writing triggers so cant understand whats wrong here.Please help
I have just started off learning triggers and I wrote a trigger but it is not working.Please find the trigger I wrote below.Let me know what is wrong on this one :

trigger OpportunityCreator on Account (After Insert) {

list<Opportunity> LstOpps = new list<Opportunity>();

for(Account acct : Trigger.new){
Opportunity Opps = new Opportunity();
Opps.StageName = 'Open';
Opps.Name = 'New Opportunity';
Opps.CloseDate = Date.newinstance(2017,02,21);
LstOpps.add(Opps);



Insert LstOpps;

}

 
I need help with making 2 custom fields created to be required if the Do not create Opp checkbox is not checked. If it is checked then the 2 fields shud be required. I also need to map the value of these fields to 2 custom fields in Opportunity. Code from Class below : 
 
public with sharing class ConvertLeadExtn
{
    Final Lead curLead;
    public boolean IsSendEmailChecked{get;set;}
    public String SelectedAccType{get;set;}
    public Contact ContactAcctToRefer{get;set;}
    public boolean IsOppChecked{get;set;}
    public String SelectedConvrtdStatus{get;set;}
    
    //Returns the list of account types
    public list<selectOption> lstAccountType
    {
        get
        {
            List<selectOption> lstAcctType = new List<selectOption>();
            lstAcctType.add(new selectOption('','--None--'));
            lstAcctType.add(new selectOption('Create New Account','Create New Account'));
            lstAcctType.add(new selectOption('Attach to Existing','Attach to Existing'));
            return lstAcctType;
        }
        set;
    }
    
    // Returns the converted Status list
    public List<selectOption> lstConvertedStatusList
    {
        get
        {
            List<selectOption> lstConvertedStatus = new List<selectOption>();
            LeadStatus leadStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];
            lstConvertedStatus.add(new selectOption(leadStatus.MasterLabel,leadStatus.MasterLabel));
            return lstConvertedStatus;
        }
        set;
    }
     
    //Controller
    public ConvertLeadExtn(ApexPages.StandardController controller)
    {
        this.curLead = (Lead)controller.getRecord();
        if(curLead.Id!=null)
        {
            ContactAcctToRefer = new Contact();
        }
    }
           
    //Converts the Lead
    public PageReference ConvertLead()
    {
        Id accountId;
        PageReference accPage;
        try
        {
            Database.LeadConvert leadCnvrt = new database.LeadConvert();
            if(SelectedAccType == null || SelectedAccType =='')
            {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Select Account Type!'));
                return null;
            }
            
            //Sets all the fields that are required
            leadCnvrt.setLeadId(curLead.Id);
            leadCnvrt.setOwnerId(curLead.OwnerId);
            leadCnvrt.setSendNotificationEmail(IsSendEmailChecked);            
            leadCnvrt.setDoNotCreateOpportunity(IsOppChecked);
            leadCnvrt.setConvertedStatus(SelectedConvrtdStatus);
           
            if(SelectedAccType == 'Attach to Existing')
            {
                if(ContactAcctToRefer.accountId !=null)
                {
                    leadCnvrt.setAccountId(ContactAcctToRefer.accountId);
                }
                else
                {
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Select Existing account to attach!'));
                    return null;
                }
            }
            
            if(!leadCnvrt.isDoNotCreateOpportunity())
            {
                leadCnvrt.setOpportunityName(curLead.Company);
            }
            
            Database.LeadConvertResult leadCnvrtResult = Database.convertLead(leadCnvrt);
            accountId=leadCnvrtResult.getAccountId();
            System.assert(leadCnvrtResult.isSuccess());
        }
        catch(exception excptn)
        {
            String excptnMsg = excptn.getMessage();
                     
            if(excptnMsg.contains('CANNOT_UPDATE_CONVERTED_LEAD') || excptnMsg.contains('INVALID_CROSS_REFERENCE_KEY'))
            {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Lead Conversion Failed! Lead is already converted!'));
            }
            else if(excptnMsg.contains('TRANSFER_REQUIRES_READ'))
            {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Opportunity can not be created, User do not have Read Permission!'));
            }
            else
            {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,excptn.getMessage()));
            }
        }
        if(accountId!=null)
        {
            accPage = new pageReference('/'+accountId);
        }
        return accPage;
    }
}

 
I need help with making 2 custom fields created to be required if the Do not create Opp checkbox is not checked. If it is checked then the 2 fields shud be required. I also need to map the value of these fields to 2 custom fields in Opportunity. Code from Class below : 
 
public with sharing class ConvertLeadExtn
{
    Final Lead curLead;
    public boolean IsSendEmailChecked{get;set;}
    public String SelectedAccType{get;set;}
    public Contact ContactAcctToRefer{get;set;}
    public boolean IsOppChecked{get;set;}
    public String SelectedConvrtdStatus{get;set;}
    
    //Returns the list of account types
    public list<selectOption> lstAccountType
    {
        get
        {
            List<selectOption> lstAcctType = new List<selectOption>();
            lstAcctType.add(new selectOption('','--None--'));
            lstAcctType.add(new selectOption('Create New Account','Create New Account'));
            lstAcctType.add(new selectOption('Attach to Existing','Attach to Existing'));
            return lstAcctType;
        }
        set;
    }
    
    // Returns the converted Status list
    public List<selectOption> lstConvertedStatusList
    {
        get
        {
            List<selectOption> lstConvertedStatus = new List<selectOption>();
            LeadStatus leadStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];
            lstConvertedStatus.add(new selectOption(leadStatus.MasterLabel,leadStatus.MasterLabel));
            return lstConvertedStatus;
        }
        set;
    }
     
    //Controller
    public ConvertLeadExtn(ApexPages.StandardController controller)
    {
        this.curLead = (Lead)controller.getRecord();
        if(curLead.Id!=null)
        {
            ContactAcctToRefer = new Contact();
        }
    }
           
    //Converts the Lead
    public PageReference ConvertLead()
    {
        Id accountId;
        PageReference accPage;
        try
        {
            Database.LeadConvert leadCnvrt = new database.LeadConvert();
            if(SelectedAccType == null || SelectedAccType =='')
            {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Select Account Type!'));
                return null;
            }
            
            //Sets all the fields that are required
            leadCnvrt.setLeadId(curLead.Id);
            leadCnvrt.setOwnerId(curLead.OwnerId);
            leadCnvrt.setSendNotificationEmail(IsSendEmailChecked);            
            leadCnvrt.setDoNotCreateOpportunity(IsOppChecked);
            leadCnvrt.setConvertedStatus(SelectedConvrtdStatus);
           
            if(SelectedAccType == 'Attach to Existing')
            {
                if(ContactAcctToRefer.accountId !=null)
                {
                    leadCnvrt.setAccountId(ContactAcctToRefer.accountId);
                }
                else
                {
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Select Existing account to attach!'));
                    return null;
                }
            }
            
            if(!leadCnvrt.isDoNotCreateOpportunity())
            {
                leadCnvrt.setOpportunityName(curLead.Company);
            }
            
            Database.LeadConvertResult leadCnvrtResult = Database.convertLead(leadCnvrt);
            accountId=leadCnvrtResult.getAccountId();
            System.assert(leadCnvrtResult.isSuccess());
        }
        catch(exception excptn)
        {
            String excptnMsg = excptn.getMessage();
                     
            if(excptnMsg.contains('CANNOT_UPDATE_CONVERTED_LEAD') || excptnMsg.contains('INVALID_CROSS_REFERENCE_KEY'))
            {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Lead Conversion Failed! Lead is already converted!'));
            }
            else if(excptnMsg.contains('TRANSFER_REQUIRES_READ'))
            {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Opportunity can not be created, User do not have Read Permission!'));
            }
            else
            {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,excptn.getMessage()));
            }
        }
        if(accountId!=null)
        {
            accPage = new pageReference('/'+accountId);
        }
        return accPage;
    }
}

 
Hi there

I am setting up a formula whereby when a certain field is changed (picklist field), the date & time of the last change is returned. My question is how to best capture all the picklist values? 

Should  I use ISPICKVAL/TEXT/CASE? Also, is ISCHANGED necessary here?

AND

ISCHANGED(D2L_Status__c)
CASE(D2L_Status__c,'Draft','Draft – Queried Supplier','Draft – Under Investigation','Input','Input – Queried Supplier','Input – Under Investigation','Pending Live Registration','Pending Live – Queried Supplier','Live','Rejected by Supplier','Rejected by Supplier – Queried Supplier','Rejection – 2nd Request','Rejection – 3rd Request','Transfer Re-application Requested','Objection Reason Request Sent','Objection – Awaiting LOA','Objection Actioned','LOA Obtained - Objection Reason Request Sent','Objection – Awaiting AM/Customer Action','Objection - Awaiting AM/Customer Feedback','Objection – 2nd Request','Objection – 3rd Request','Re-applied for Objection','Objection Complete','Objection Upheld - CLPW'


TIA
 
Hi all, 

Need some assistance and easiest, preferably no code, way of doiing the following

We have the following fields at present
Age_c
Birthdate
U18_subscribed_c
Deceased_c

We need to update the U18_subscribed_c checkbox to false when the following applies

Birthdate is blank
Age is 18 but in the year of their 19th birthday
Deceased is false

If the date hits 01/01 of the year of the contacts 19th birthday the U18_subscribe_c should update to false
If the Deceased field is set at true the U18_subscribe_c should update to false
If the Birthdate field is completed the above should calculate correctly

Any suggestions will be appreciated
Hi everybody,

I just started as an SF admin and I'm having a hard time with the configurating process of the clients org. It seemed simple to start with, but now I find it hard to apply to their (many!) specific requests.

For example, the client wants the Initials field in Contacts automatically updated (according to the firstname of the Contact). So firstname Bob updates to B. as an initial in the initial field.

Do I need to create a trigger for this to happen (never created a trigger before)?

Any help is appreciated!

Thanks!
Hi,

On my custom object, I have created a lookup to the user. This field shows a picklist with 3 options namely  "User", "Partner User", "Customer Portal User". I want only "User" option to be visible in the picklist. Is this possible? If yes please tell me how could I do this.

Thanks,
Vijay
Hi ,
I am trying to create a validation rule where the Stage is Tommorow and if the Date is not equal to tommorw then Error should display as "select tommorws date ".Can any one help

ISPICKVAL( Stage__c, "Schedule given for tomorrow")   && (Date_and_Time__c   !=  NOW()+1)
Hallo all,
Is it possible to change the picklist value automatically, if current time exceeds the start time field(DateTime Datatype) value by 15 minutes. This condition should be automatically updated to all the records of the object.
Thank you.
I am getting the following error :
Error: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CreateActivityOnLeadConverted: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.CreateActivityOnLeadConverted: line 34, column 1: [] Class.leadconvert.BulkLeadConvert.handleOpportunityInserts: line 740, column 1 Class.leadconvert.BulkLeadConvert.convertLead: line 104, column 1

Below is the trigger I think is the problem but not sure Please help.
 
trigger CreateActivityOnLeadConverted on Opportunity (after insert) {
    
    List<Task> tasksToInsert = new List<Task>();
    List<User> usersToUpdate = new List<User>();
    List<Lead_Quota_Audit__c> lstNewAudits = new List<Lead_Quota_Audit__c>();
    
    Id wholsaleID = null;
    List <RecordType> wId = [Select Id From RecordType where sobjecttype = 'Opportunity' and name = 'Wholesale' limit 1];
    if ((wId != null) && (wId.size() == 1)) wholsaleID = wId[0].Id;
    
    Set<Id> userIds = new Set<Id>();
    for(Opportunity opp : Trigger.new){
        userIds.add(opp.OwnerId);
    }
    
    Map<Id, User> usersById = new Map<Id, User>([SELECT Id, Name, Leads_Assigned_Current_Month__c, Leads_Assigned_Current_Week__c FROM User  WHERE Id IN :userIds]);
    
    for(Opportunity opp : Trigger.new){
        if (opp.RecordTypeId != wholsaleID) {    
            if (opp.ConvertedLeadID__c != null) {
                Task task = new Task(
                    Type = 'Call',
                    Subject = 'Lead Status Changed to Converted',
                    ActivityDate = Date.Today(),
                    WhatId = opp.Id,
                    OwnerId = UserInfo.getUserId(),
                    Status = 'Completed', 
                    Call_Screener_Transfered__c = opp.CS_Transferred__c 
                );
                tasksToInsert.add(task);
                if(opp.Lead_Status__c == 'Open'){
                    User u = usersById.get(opp.OwnerId);
                    if(u != null){
                        u.Leads_Assigned_Current_Month__c++;
                        u.Leads_Assigned_Current_Week__c++;
                        usersToUpdate.add(u);
                        Lead_Quota_Audit__c audit = new Lead_Quota_Audit__c(
                            Lead__c = opp.ConvertedLeadID__c,
                            User__c = u.Id,
                            Old_Owner__c = u.Name
                        );
                        lstNewAudits.add(audit);
                        
                    }
                }
            }
        }
    }
    
    insert tasksToInsert;
    update usersToUpdate;
    if(lstNewAudits.size() > 0) {
        insert lstNewAudits;
    }

}

 
Please Help

Trying to set a reminder for a task created in process builder the field is [Media_Event__c].Copy_Deadline_Date__c =

and I need it to fire the reminder if the date is 7 days or less?

User-added image
The error I am getting is  :

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger hybinjoseph1.AcctTrigger caused an unexpected exception, contact your administrator: hybinjoseph1.AcctTrigger: execution of AfterInsert caused by: System.FinalException: Cannot modify a collection while it is being iterated.: Trigger.hybinjoseph1.AcctTrigger: line 9, column 1

and my tirgger is :

trigger AcctTrigger on Account (After Insert) {

list<contact> conlist = new list<contact>();

for(Account a : trigger.new){

conlist = [SELECT AccountID, Name from Contact WHERE Mailingcity = :a.Billingcity];

for(contact con : conlist){
con.AccountId = a.Id;
conlist.add(con);

}


}
update conlist;

}



I am new to writing triggers so cant understand whats wrong here.Please help
I have just started off learning triggers and I wrote a trigger but it is not working.Please find the trigger I wrote below.Let me know what is wrong on this one :

trigger OpportunityCreator on Account (After Insert) {

list<Opportunity> LstOpps = new list<Opportunity>();

for(Account acct : Trigger.new){
Opportunity Opps = new Opportunity();
Opps.StageName = 'Open';
Opps.Name = 'New Opportunity';
Opps.CloseDate = Date.newinstance(2017,02,21);
LstOpps.add(Opps);



Insert LstOpps;

}