• Teja Sattoor
  • NEWBIE
  • 15 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 4
    Replies
Hi,

I used process builder to update fields on contacts when created. I noticed that this only works 80% of the times, and does not update those fields rest of the times. I have tried to look at the logs, but all it says was that the "WF RULE IS EVALUATED TO TRUE", and moved onto the next process without updating the fields. I am also triggering some time-based flows from the same process for some context.

User-added image

User-added image

User-added image

User-added image

User-added image

Could you please help me fix it?

Thank you in advance!!
Hi,

I am trying to see if could use a formula field to get the Subscription End Date based on the Account's Sign Up Date(not the current renewal start date). This is what I came up with

```IF(ISPICKVAL( SaaS_Lifecycle_Stage__c, "SaaS Customer" ),

IF(ISPICKVAL( Annual_Contract__c , "Yes"),
IF(DATE(YEAR(TODAY()),MONTH(Sign_Up_Date__c ),DAY(Sign_Up_Date__c )) <= TODAY(), DATE(YEAR(TODAY())+1,MONTH(Sign_Up_Date__c ),DAY(Sign_Up_Date__c))-1, 
DATE(YEAR(TODAY()),MONTH(Sign_Up_Date__c ),DAY(Sign_Up_Date__c ))-1),

IF(DATE(YEAR(TODAY()),MONTH(TODAY()),DAY(Sign_Up_Date__c )) <= TODAY(), DATE(YEAR(TODAY()),MONTH(TODAY()),DAY(Sign_Up_Date__c))+29, 
DATE(YEAR(TODAY()),MONTH(TODAY()),DAY(Sign_Up_Date__c ))-1)),NULL)```

The problem with the above formula is that the Subscription End Date changes for Monthly subscriptions(lower half od the formula) based on if the day(sign up date) has passed or not in that particular month.

Thanks,
Teja
Hi,

We recently made the change to work from contacts instead of leads in Salesforce. We get all our contacts from our marketing generation tool without an Account. The company name of these contacts is stored in a field called "Company__c". I wrote a code that looks if the contact is from our existing customer (Zlien_User_ID__c) and associates with the same Salesforce Account(User_ID__c), if not it will look for the matching Account name and associates with it, and if not finally it will create an account and associate with it. The following code works fine when one contact is created by the lead gen tool at a time. Sometimes, we may have to bulk upload contacts using dataloader which is when I encounter the error message: System.LimitException: Too many query rows: 50001. 

Please find the Code below:

public class assignAccount
{
    public static void assignAccounts(Set<Id> contactIds) 
    {

        Map<String,Account> matchUserIdMap = new Map<String,Account>();
        Map<String,Account> matchCompanyMap = new Map<String,Account>();
        
        for(Account acc : [Select User_ID__c, name, Id from Account])
        {
            if(acc.User_ID__c != null)
            {
                // Contact map when Zlien user id is not null.
                matchUserIdMap.put(acc.User_ID__c, acc);
            }
            else
            {
                // Contact map when Zlien user id is null.
                matchCompanyMap.put(acc.name, acc);
            }
            
        }
       
        for(Contact con : [Select Zlien_User_ID__c, Company__c, accountId, ownerId from Contact where Id IN :contactIds])
        {
            if(con.Zlien_User_ID__c != null)
            {
                if(matchUserIdMap.containsKey(con.Zlien_User_ID__c))
                {
                   con.accountId = matchUserIdMap.get(con.Zlien_User_ID__c).Id;
                }
                
                else if(matchCompanyMap.containsKey(con.Company__c))
                {
                    con.accountId = matchCompanyMap.get(con.Company__c).Id;
                }
                
                else
                {
                    Account A = new Account(name = con.Company__c, ownerId = con.ownerId);
                    insert A;
                    con.accountId = A.Id;
                }
            }
            else if(con.Company__c != null)
            {
                if(matchCompanyMap.containsKey(con.Company__c))
                {
                    con.accountId = matchCompanyMap.get(con.Company__c).Id;
                }
                
                else
                {
                    Account A = new Account(name = con.Company__c, ownerId = con.ownerId);
                    insert A;
                    con.accountId = A.Id;
                }
            }
            
            update con;          
        }
         
    }
    
}

Thanks in Advance,
Teja
Hi, I am new to SF coding and I have written a lead conversion trigger that should convert a lead when it meets the criteria. My code works fine when I convert one lead at a time, but runs into "CANNOT_CONVERT_UPDATE_LEAD" when I run to convert multiple leads at once. Please find my trigger and apex class below.

Apex Trigger:
trigger AutoConvertLeads on Lead (after update) {

    Set<Id> leadIds = new Set<Id>();
    
    for(Lead myLead : Trigger.new){
    
        if((myLead.isconverted == false) && (myLead.Convert_to_Contact__c == true)){
            
            leadIds.add(myLead.Id);
            
        }
        
    if(leadIds.size() > 0) {
        
        LeadConversionUtils.convertLeads(leadIds);
    }
    }
}

Apex Class:
public class LeadConversionUtils {

    public static void convertLeads(Set<Id> leadIds) {
    
        // Retrieve all the necessary fields for the Leads to be converted
        List<Lead> leadList = new List<Lead>([SELECT Id, Company, Zlien_User_ID__c FROM Lead WHERE Id IN :leadIds]);
              
             
         //Convert the lead
       for(lead myLead : leadList){ 
        
            List<Account> AccountList1 = [Select Account.Id, Account.Name from Account where Account.User_ID__c =: myLead.Zlien_User_ID__c];
            if(!AccountList1.isEmpty()){
                List<Contact> ContactList = new List<Contact>();
                List<Account> AccountList = new List<Account>();   
        
                for(Account acc1 : AccountList1){
                    Database.LeadConvert lc = new database.LeadConvert();
                    lc.setLeadId(myLead.Id);
                    lc.setAccountId(acc1.Id);
                    lc.setConvertedStatus('Converted to Opportunity');
        
                    lc.setDoNotCreateOpportunity(true);
                    Database.LeadConvertResult lcr = Database.convertLead(lc);
                    System.assert(lcr.isSuccess());
                    
                    Contact Con = [Select OwnerId, Lead_Status__c, Contact_Stage__c from Contact where Contact.Id =: lcr.getContactId()];
                    Account Acc = [Select OwnerId from Account where Account.Id =: lcr.getAccountId()];
                    Con.Lead_Status__c = 'Converted to Account/Contact';
                    Con.Contact_Stage__c = 'Current Customer';
                    Con.OwnerId = Acc.OwnerId;
                    ContactList.add(Con);
                    AccountList.add(Acc);
    
                }   
                
                update ContactList;
                update AccountList;     
            }
        }   
    }
}


Could you please help me bulkify the trigger and also let me know the mistake I have been doing? Thanks
Can someone help me identify what could be the problem.

I have written an apex trigger to convert a lead to contact/account when a checkbox evaluates to true. The formula for the checkbox is TRUE when it is not assigned to the 'default queue' or to the 'default user' who get leads assigned from an integration with Hubspot. We have a Lead Assignment Rule that assigns these leads to 'certain users' or to the default queue. 

So technically, my formula should be evaluated to true only when it is assigned to these 'certain users'. It is working absolutely fine when I test in sandbox which is not connected to hubspot. When I pushed it to production and we get leads from hubspot, the checkbox is always evaluated to TRUE and is converting the contacts assigning them on a random basis. I was just hoping to get a clear idea on the Lead Assignment Rule that might be causing the formula to TRUE at an instance.

Thanks in advance!!
Hi,

We recently made the change to work from contacts instead of leads in Salesforce. We get all our contacts from our marketing generation tool without an Account. The company name of these contacts is stored in a field called "Company__c". I wrote a code that looks if the contact is from our existing customer (Zlien_User_ID__c) and associates with the same Salesforce Account(User_ID__c), if not it will look for the matching Account name and associates with it, and if not finally it will create an account and associate with it. The following code works fine when one contact is created by the lead gen tool at a time. Sometimes, we may have to bulk upload contacts using dataloader which is when I encounter the error message: System.LimitException: Too many query rows: 50001. 

Please find the Code below:

public class assignAccount
{
    public static void assignAccounts(Set<Id> contactIds) 
    {

        Map<String,Account> matchUserIdMap = new Map<String,Account>();
        Map<String,Account> matchCompanyMap = new Map<String,Account>();
        
        for(Account acc : [Select User_ID__c, name, Id from Account])
        {
            if(acc.User_ID__c != null)
            {
                // Contact map when Zlien user id is not null.
                matchUserIdMap.put(acc.User_ID__c, acc);
            }
            else
            {
                // Contact map when Zlien user id is null.
                matchCompanyMap.put(acc.name, acc);
            }
            
        }
       
        for(Contact con : [Select Zlien_User_ID__c, Company__c, accountId, ownerId from Contact where Id IN :contactIds])
        {
            if(con.Zlien_User_ID__c != null)
            {
                if(matchUserIdMap.containsKey(con.Zlien_User_ID__c))
                {
                   con.accountId = matchUserIdMap.get(con.Zlien_User_ID__c).Id;
                }
                
                else if(matchCompanyMap.containsKey(con.Company__c))
                {
                    con.accountId = matchCompanyMap.get(con.Company__c).Id;
                }
                
                else
                {
                    Account A = new Account(name = con.Company__c, ownerId = con.ownerId);
                    insert A;
                    con.accountId = A.Id;
                }
            }
            else if(con.Company__c != null)
            {
                if(matchCompanyMap.containsKey(con.Company__c))
                {
                    con.accountId = matchCompanyMap.get(con.Company__c).Id;
                }
                
                else
                {
                    Account A = new Account(name = con.Company__c, ownerId = con.ownerId);
                    insert A;
                    con.accountId = A.Id;
                }
            }
            
            update con;          
        }
         
    }
    
}

Thanks in Advance,
Teja
Hi, I am new to SF coding and I have written a lead conversion trigger that should convert a lead when it meets the criteria. My code works fine when I convert one lead at a time, but runs into "CANNOT_CONVERT_UPDATE_LEAD" when I run to convert multiple leads at once. Please find my trigger and apex class below.

Apex Trigger:
trigger AutoConvertLeads on Lead (after update) {

    Set<Id> leadIds = new Set<Id>();
    
    for(Lead myLead : Trigger.new){
    
        if((myLead.isconverted == false) && (myLead.Convert_to_Contact__c == true)){
            
            leadIds.add(myLead.Id);
            
        }
        
    if(leadIds.size() > 0) {
        
        LeadConversionUtils.convertLeads(leadIds);
    }
    }
}

Apex Class:
public class LeadConversionUtils {

    public static void convertLeads(Set<Id> leadIds) {
    
        // Retrieve all the necessary fields for the Leads to be converted
        List<Lead> leadList = new List<Lead>([SELECT Id, Company, Zlien_User_ID__c FROM Lead WHERE Id IN :leadIds]);
              
             
         //Convert the lead
       for(lead myLead : leadList){ 
        
            List<Account> AccountList1 = [Select Account.Id, Account.Name from Account where Account.User_ID__c =: myLead.Zlien_User_ID__c];
            if(!AccountList1.isEmpty()){
                List<Contact> ContactList = new List<Contact>();
                List<Account> AccountList = new List<Account>();   
        
                for(Account acc1 : AccountList1){
                    Database.LeadConvert lc = new database.LeadConvert();
                    lc.setLeadId(myLead.Id);
                    lc.setAccountId(acc1.Id);
                    lc.setConvertedStatus('Converted to Opportunity');
        
                    lc.setDoNotCreateOpportunity(true);
                    Database.LeadConvertResult lcr = Database.convertLead(lc);
                    System.assert(lcr.isSuccess());
                    
                    Contact Con = [Select OwnerId, Lead_Status__c, Contact_Stage__c from Contact where Contact.Id =: lcr.getContactId()];
                    Account Acc = [Select OwnerId from Account where Account.Id =: lcr.getAccountId()];
                    Con.Lead_Status__c = 'Converted to Account/Contact';
                    Con.Contact_Stage__c = 'Current Customer';
                    Con.OwnerId = Acc.OwnerId;
                    ContactList.add(Con);
                    AccountList.add(Acc);
    
                }   
                
                update ContactList;
                update AccountList;     
            }
        }   
    }
}


Could you please help me bulkify the trigger and also let me know the mistake I have been doing? Thanks