• Dhanraj Poojary 18
  • NEWBIE
  • 25 Points
  • Member since 2018
  • Salesforce Developer
  • Cymetrixsoft

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 14
    Replies
Can someone help me understand what this apex trigger is doing? Someone set this up in our org, in the event object and having a hard time understanding what its doing: 
 
trigger Events on Event (before insert, before update, after insert, after delete) 
{

  if ( trigger.isBefore)
  {
    if ( trigger.isInsert || trigger.isUpdate)
    {
      if(AccountCallRollup.batch_update_running!=true)
        {
        //Events.ActivityCallRollup(Trigger.new);
        }

      Events.PopulateActivityFields( trigger.new );
    //5/5/2018: Consolidated from separate trigger
      Events.Event_User_field_from_Assigned_To_Before(Trigger.new);
    }

    //if(trigger.isDelete && AccountCallRollup.batch_update_running!=true)
    //  {
    //  Events.ActivityCallRollup(Trigger.old);
    //  }

  }

  if ( trigger.isAfter)
  {
    if ( trigger.isInsert || trigger.isUpdate)
    {
    //5/5/2018: Consolidated from separate trigger
      Events.Event_User_field_from_Assigned_To_After(Trigger.new);
    if(AccountCallRollup.batch_update_running!=true)
      {
      //6/22/18: Turn off immediate rollup
      //Events.ActivityCallRollup(Trigger.new);
      }
    } 
  }

    if(AccountCallRollup.batch_update_running!=true && trigger.isDelete)
      {
      //6/22/18: Turn off immediate rollup
      //Events.ActivityCallRollup(Trigger.old);
      }


}

 
I'm trying to auto update a field on my accounts based on the last time a new opportunity was created for that account and on the account's annual revenue.  For example, account A has annual revenue greater than $250 million and hasn't had a new opportunity created in 2 months.  At the two month mark of no new opportunities, I'd like to update the account's "rating" field to a certain picklist value.  If the same account reaches the 4 month mark, I'd like to update the "rating" field again to a different picklist value.  If the account does not meet the annual revenue criteria (say it was under the $250 million threshold), then the trigger ignores it.  Any suggestions?  I'm new to triggers and apex code so would appreciate any help.  Thanks!
Hi All,
Below is my Apex Code which I have created to auotmate Lead Conversion to Account and Contact:

Public class AutoConvertLeads
{
    @InvocableMethod //Used to invoke this Class in Process Builder
    public static void LeadAssign(List<Id> LeadIds)
    {
     map< id,id> mapAccount = new map<id,id>();
     {
       for(Account a : [SELECT id,Company_Name_Custom__c from Account])
        {
         mapAccount.put(a.Company_Name_Custom__c, a.id);
        }

        LeadStatus CLeadStatus= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted = true LIMIT 1];
        List<Database.LeadConvert> MassLeadconvert = new List<Database.LeadConvert>();
        for(Lead currentlead: [SELECT Id,Company_Name_Custom__c from Lead where Id in:LeadIds ])
     {
         if( !mapAccount.isEmpty() && mapAccount.ContainsKey(currentlead.Company_Name_Custom__c) )
         {
            Database.LeadConvert Leadconvert = new Database.LeadConvert();
                Leadconvert.setLeadId(currentlead.Id);                
                Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
                Leadconvert.setDoNotCreateOpportunity(TRUE);
                Leadconvert.setAccountId(mapAccount.get(currentlead.Company_Name_Custom__c));
                MassLeadconvert.add(Leadconvert);
             
         }
         else
         {
            Database.LeadConvert Leadconvert = new Database.LeadConvert();
                Leadconvert.setLeadId(currentlead.Id);                
                Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
                Leadconvert.setDoNotCreateOpportunity(TRUE);
                MassLeadconvert.add(Leadconvert);
         }
      }

        
        if (!MassLeadconvert.isEmpty())
        {
            List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);
        }
    }   }    
}

The code is working fine but I have 1 problem with it:

The converted contact is always attaching to the Same account no matter which account name you put in the company for the lead conversion.

Below is my requirement:
" Our leads flow into Salesforce from Admin Panel/HubSpot. Custom Company Name is a common Lead field for both HubSpot and Salesforce. When the Lead is created by flowing into Salesforce, the standard Company field of Lead is blank or [not provided].

We also have a check box on the Lead named: Created in Panel.


What we want is to convert only those leads which have this Created in Admin Panel checkbox true. Also, on conversion, the value in the Custom Company Name should overwrite the Company of the Lead thereby replacing it as Account Name on the Converted Contact.

Then, if the Account already exists, it should only create a contact and attach to the existing Account.
"

Can anyone of you help me with tweaking the code to meet my above requirement.

Appreciate your help and prompt response.

Thanks!
TS
So I have an object called Purchase Requisition that has a button that leads the user to a pop up visualforce page where they select a Warehouse from a picklist which is another custom object. The picklist is generated by all of the records in the Warehouse object. I had to do this because users don't have access to Warehouse due to the cost of licensing. I want whatever their selection is on that window and then hit save, to then save the warehouse name as a text field on the purchase requisition records that they started with. I'm not really sure how to go about that. Here is the VF page and controller that I have built so far. Any help is appreciated!
 
public class selectWarehouse {
    private final Purchase_Requisition__c pr;
    
    public selectWarehouse(ApexPages.StandardController stdController) {
        this.pr = (Purchase_Requisition__c)stdController.getRecord();
    }
    public string selectedWarehouse{get;set;}
    
    public list<SelectOption> getWarehousenames() {
        List<SelectOption> options = new List<SelectOption>();
        for (Warehouse__c w : [select name from Warehouse__c order by name desc limit 100])
        {
            options.add(new SelectOption(w.name, w.name));
        }
        return options;
    }
}
 
<apex:page lightningStylesheets="true" standardController="Purchase_Requisition__c" extensions="selectWarehouse" showHeader="false">
    <apex:form >
        <apex:pageBlock title="Select A Warehouse">
            <apex:outputLabel value="Warehouse "/>
            <apex:selectList size="1">
                <apex:selectOptions value="{!Warehousenames}">
                </apex:selectOptions>
            </apex:selectList>
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page

 
Apex Class

trigger updateDetails on WLog__c (after update) 
{
    List<id> caseIds = new List<id>();
    List<id> ParentCaseids = new List<id>();
    List<case> parentchildlist = new List<case>();
    List<case> updcaselist=new List<case>();
    Set<String> gbS = SMCaseUtils.getSalesOrgs('GB');

    if(trigger.isAfter && trigger.isUpdate)
    {
        for(WLog__c olog : trigger.new)        
        {
            if(olog.Result__c == 'Success' && olog.Date_Issued__c != null)
                caseIds.add(olog.Case__c);
        }
        system.debug('case ids from olog -->'+caseIds);
        if(!caseIds.isEmpty()){
            for(Case cs :[select id, ParentId, SV_Parent_Case__c from case where id in :caseIds AND Reasons__c = 'System Generated' AND Org_From_IP__c in :gbS]){
                if(cs.SV_Parent_Case__c){
                    ParentCaseids.add(cs.id);
                }else
                {
                    if(cs.parentId!=null){
                        ParentCaseids.add(cs.ParentId);
                    }else
                    {
                        ParentCaseids.add(cs.id);

                    }
                }          
            }
        }
        system.debug('parent ids list -->'+ParentCaseids);   
        if(!ParentCaseids.isEmpty()){
            parentchildlist=[select id,Reasons__c,CC_Overview_Status__c,(select id,CC_Completed_On__c from Cases) from case where id in :ParentCaseids];
        }
        system.debug('parent child list -->'+parentchildlist);
        for(Case parent : parentchildlist)
        {
            Boolean isDateNull=false;
            for(Case child : parent.cases)
            {
                if(child.CC_Completed_On__c==null)
                {
                    isDateNull=true;
                    break;
                }
            }
            if(isDateNull==false)
            {
                parent.CC_Overview_Status__c='Process Complete';
                updcaselist.add(parent);
            }   
        }
        if(!updcaselist.isEmpty())
        {
            system.debug('inside update for case list in olog-->'+updcaselist);
            update updcaselist;

        }
    }
}



Test class


@isTest(seeAllData=true)
public class updateDetailsTest
{
    static testMethod void ParentCaseTestMethod1()
    {
        Test.startTest();
        List<WLog__c> ologlist =[select id,Case__c,Result__c,Date_Issued__c from WLog__c limit 1];   
            if(!ologlist.isEmpty())
            {
                ologlist[0].Date_Issued__c=system.today();
                ologlist[0].Result__c='Success';
                update ologlist;
            }    
        Test.stopTest();
    }
    static testMethod void ParentCaseTestMethod()
    {
        Test.startTest();
        Set<String> gbS = SMCaseUtils.getSalesOrgs('GB');
        List<Case> cs=[select id, ParentId, SV_Parent_Case__c,CCDetails__c from case where 
        Reasons__c = 'System Generated' AND Org_From_IP__c in :gbS AND CCDetails__c!=null
        limit 1];
        if(!cs.isEmpty())
        {
            List<WLog__c> ologlist =[select id,Case__c,Result__c,Date_Issued__c from WLog__c 
            where Case__c=:cs[0].CCDetails__c limit 1];   
            if(!ologlist.isEmpty())
            {
                ologlist[0].Date_Issued__c=system.today();
                ologlist[0].Result__c='Success';
                update ologlist;
            }
        }
        Test.stopTest();
    }
}


The underlined bold italic part of the apex class not covered in the test class please help me out..
This is my SOSL:
List<List<sObject>> searchList=[Find :searchstring IN ALL FIELDS 
RETURNING  Product2(ProductCode,Name,ImageName__c), PricebookEntry(UnitPrice)];

Occur error:
entity type PricebookEntry does not support search

How can search product ?
Can someone help me understand what this apex trigger is doing? Someone set this up in our org, in the event object and having a hard time understanding what its doing: 
 
trigger Events on Event (before insert, before update, after insert, after delete) 
{

  if ( trigger.isBefore)
  {
    if ( trigger.isInsert || trigger.isUpdate)
    {
      if(AccountCallRollup.batch_update_running!=true)
        {
        //Events.ActivityCallRollup(Trigger.new);
        }

      Events.PopulateActivityFields( trigger.new );
    //5/5/2018: Consolidated from separate trigger
      Events.Event_User_field_from_Assigned_To_Before(Trigger.new);
    }

    //if(trigger.isDelete && AccountCallRollup.batch_update_running!=true)
    //  {
    //  Events.ActivityCallRollup(Trigger.old);
    //  }

  }

  if ( trigger.isAfter)
  {
    if ( trigger.isInsert || trigger.isUpdate)
    {
    //5/5/2018: Consolidated from separate trigger
      Events.Event_User_field_from_Assigned_To_After(Trigger.new);
    if(AccountCallRollup.batch_update_running!=true)
      {
      //6/22/18: Turn off immediate rollup
      //Events.ActivityCallRollup(Trigger.new);
      }
    } 
  }

    if(AccountCallRollup.batch_update_running!=true && trigger.isDelete)
      {
      //6/22/18: Turn off immediate rollup
      //Events.ActivityCallRollup(Trigger.old);
      }


}