• Prem R
  • NEWBIE
  • 10 Points
  • Member since 2018
  • Tech Consultant

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 17
    Replies
Hi, 
I am currently having issue with my code, not sure how to finish it. 

I want to assign round robin opportunity to a lead object only if its status is working and the user is round robin available. I want to assign this to every new lead. If there are no available users put the lead in Queue, and when a user is available assign it to one with the least amount of leads. I have attached my code below. The comments is where i am stuck. Any help is appreciated, thank you. 
trigger WebToLeadRoundRobinTrigger on Lead (after insert, after update, before insert, before update) 
{	
	List<Lead> newLeadLst = new List<Lead>();
	
	if(Trigger.isBefore && Trigger.isInsert)
	{
		for (Lead newLead : Trigger.new)
		{
			if (newLead.Status.equalsIgnoreCase('New') && newLead.LeadSource.equalsIgnoreCase('Website'))
			{
				newLeadLst.add(newLead);
			}
				
            //Grabs the user where it is round robin avaialble 
			List<User> lsAvailableUsers = [SELECT Id, Name, Robin_Counter__c, Is_Available_Round_Robin__c
										FROM User 
										WHERE Is_Available_Round_Robin__c = true
										ORDER BY Robin_Counter__c ASC
			];

			if(lsAvailableUsers != null && lsAvailableUsers.size() > 0)
			{
				Integer currentMaxRobinCounter = lsAvailableUsers[lsAvailableUsers.size()-1].Robin_Counter__c.intValue(); 
                Integer nextUser = 0;
		          	  
				if(currentMaxRobinCounter == null) 
				{     
					currentMaxRobinCounter = 0; 
				}
		              
				for(Lead newLeadFromWeb : newLeadLst)
				{
					newLeadFromWeb.ownerid = lsAvailableUsers[nextUser].id;
					nextUser = math.mod((nextUser + 1), lsAvailableUsers.size());
					lsAvailableUsers[nextUser].Robin_Counter__c = currentMaxRobinCounter + nextUser + 1;
					update lsAvailableUsers;  
				}			
			} 
			else
			{   
            
            /* how can i assign leads to user with the least amount of leads? I want to query a list of users where Is_Available_Round_Robin__c = true and map it   
                to a list of leads with status = working. I should have ownerid as 1st column of the query and then the number of leads the owner currently have
                for the 2nd column. Need to somehow convert this soql to a map */
       
				//if the list size = 0 assign it to ownerID = Queue
				
				Group listEmptyFreeUserInQueue = [SELECT Id FROM Group WHERE Type = 'Queue' AND Name = 'Web to Lead' LIMIT 1];

				for(Lead newLeadFromWeb : newLeadLst)
				{
					newLeadFromWeb.ownerid = listEmptyFreeUserInQueue.Id;
				}			
			}
		}
	}
}

Also, if I were to add this in, how would i approach this? If a lead have been left in a status ='assigned' for more than 2 hours, assign the lead to another user that is Is_Available_Round_Robin__c.

 
    public static void iqId(List<Account> iqList){
        
        for(Account eachAccount: iqList){
            if(eachAccount.IQ_ID__c!=null){
                system.debug('IQ_ID__c');
                if(!eachAccount.Sales_Ops__c){
                    
                    eachAccount.C_Name__c=eachAccount.Ultimate_Parent__c;
                    eachAccount.H_ID__c=eachAccount.Ultimate_Parent_Id__c;
                } else {
                    if (eachAccount.ParentId != null){
                        Map<string,string> ultimateDetails = getultimate(eachAccount.ParentId);
                        List<string> ultimateId = new List<string>();
                        ultimateId.addAll(ultimateDetails.keyset());
                        eachAccount.C_Name__c=ultimateDetails.values()[0];
                        eachAccount.H_ID__c=ultimateId[0];
                    }
                }
            }
        }
    }
    public static Map<string, String> getultimate(string parentAccount){
        boolean isSFDCUltimate = true;
        Map<string, string> ultimateParent = new Map<string, string>();
        while(isSFDCUltimate){
            Account temp = [select Id, Name, ParentId, IQ_ID__c from Account Where Id=:parentAccount];
            if (temp.ParentId==null){
                ultimateParent.put(temp.IQ_ID__c, temp.Name);
                break;
            }else {
                parentAccount=temp.ParentId;
            }
        }
        return ultimateParent;
    }
  • July 27, 2018
  • Like
  • 0
Hi All,

I need one workaround for one of our clients, that is explained briefly below.

User1 belongs to a customprofile1 and we have two custom apps (CustApp1 ,CustApp2).
No of record types for the Account object is 5.

Requirement :
The User1 logged in the org and will see the CustApp1 which has 2 record types for creating an account. If the User1 changed the App to custApp2, he/she need to see the other 3 record types for creating an account.

It is nothing but User1 should be able to see the record types based on the App changes. Please assist me to get a workaround for this.

Hope anyone can answer this.

Thanks,
Rakshana




 

Hello,

Taking my first shot at APEX.

I have created a Custom Field on my Quote table that determines a when a Quote can be deleted. I need my code to delete Quote records, then send an email showing how many Successes or Errors when my job completes.

Could someone be so kind as to review my code...any suggestions or comments would be appreciated.

 

Kind regrds,

Robert

global class QuoteDeleteBatchJob implements Database.Batchable<sObject> 
{
    global Database.QueryLocator start(Database.BatchableContext BC) 
    {
        String query = +
        'SELECT Id, Name, Deletable__c +
         FROM Quote__c +
         WHERE Deletable = TRUE';  
        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext BC, List<Quote__c> scope) 
    {
        for(Quote a : scope)
        {
            a.Name = a.Name + 'Deleted by QuoteDeleteBatchJob';
        }
        Delete scope;
    }
    global void finish(Database.BatchableContext BC) 
    
     AsyncApexJob a = [SELECT Id,Status,JobType,NumberOfErrors,JobItemsProcessed,TotalJobItems,CompletedDate,ExtendedStatus
     FROM AsyncApexJob WHERE Id =:BC.getJobId()];
     
     List<User> userList = new List<User>();
     userList = [SELECT Id,Email,IsActive FROM User WHERE Profile.Name = 'System Administrator' AND IsActive = True] ;
          
     // Send an email to all active Admins notifying of job completion.     
     for(User u : userList)
     
     {           
       Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
               
       //String[] toAddresses = new String[] {user.Id};
       //mail.setToAddresses(toAddresses);
       mail.setTargetObjectId(u.Id);
       mail.setSubject('QuoteDeleteBatchJob - ' + a.Status);
       mail.setSaveAsActivity(false);
       mail.setPlainTextBody
       ('The batch Apex job completed on  ' + a.CompletedDate + ',\n\n' +
        'Job Status : ' + a.Status + '\n'+
        'Total Job Items deleted : ' + a.TotalJobItems + '\n'+
        'Number of Job Items Deleted : ' + a.JobItemsProcessed + '\n' +
        'Number of Failures : '+ a.NumberOfErrors);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
     }  
          
}

 

I have a custom object names Project. When I log a call as a task, the related to is the project Id. I assume that is the WhatId field on the task object. I need to be able to also have this task show up on the accounts activity history related list as well. I have a trigger, but get the error "Field is no writeable Task.AccountId."
How do I use my extension "myController" to show information on my visual force page?
User-added image
Im wanting to pull the information up onto this screen which is my VisualForce page :-
User-added image
Here is the code for my VisualForce page:-
<apex:page lightningStyleSheets="true" StandardController="Apprentice__c" extensions="myController" title="Apprentice Documentation">
    <apex:form >
    <!--myController refers to the Apex class I created called myController.apxc this is so I can use two object types in one form in place of a Standard controller
        For refrence ApprenticeObj = new Apprentice__c and ComponentsObj = new Apprenticeship_Component__c-->
        
    <!--Style-->
        <style>
        body{
        font-family: Arial,Helvetica,sans-serif;
        color: #000000;
        Padding:25px;
        }
        </style>
    <!--End of Style-->
        
        <apex:pageBlock >
            <apex:pageBlockSection columns="3">
                <apex:inputField value="{! Apprentice__c.Name}"/>
            </apex:pageBlockSection>
         </apex:pageBlock>
        
     <!--Apprentice Details Section-->
        <apex:pageBlock title="Apprentice Details">
            <apex:pageBlockSection columns="2">
                <apex:inputField value="{! Apprentice__c.Apprentice_name__c}"/>
                <apex:inputField value="{! Apprentice__c.Curriculum_Verified__c}"/>
                <apex:inputField value="{! Apprentice__c.Employer__c}"/>
                <apex:inputField value="{! Apprentice__c.Programme_Area__c}"/>
                <apex:inputField value="{! Apprentice__c.Vacancy__c}"/>
                <apex:inputField value="{! Apprentice__c.Learning_Start_Date__c}"/>
                <apex:inputField value="{! Apprentice__c.Levy_Status__c}"/>
                <apex:inputField value="{! Apprentice__c.Programme_Agreed_With_Employer__c}"/>
                <apex:inputField value="{! Apprentice__c.Existing_Employee__c}"/>
            </apex:pageBlockSection>
         </apex:pageBlock>
        <!--End of Apprentice Details Section-->
        
        <!--Line Manager Details Section-->
         <apex:pageBlock title="Line Manager Details">
            <apex:pageBlockSection columns="2">
               <apex:inputField value="{! Apprentice__c.Line_Manager__c}"/>
               <apex:inputField value="{! Apprentice__c.Line_Manager_Phone__c}"/>
               <apex:inputField value="{! Apprentice__c.Line_Manager_Email__c}"/>
               <apex:inputField value="{! Apprentice__c.Line_Manager_Mobile__c}"/>
            </apex:pageBlockSection>
         </apex:pageBlock>
     <!--End ofLine Manager Details Section-->
        
     <!--Previous Education & Diagnostics-->
       <apex:pageBlock title="Previous Education & Diagnostics">
            <apex:pageBlockSection columns="2">
                <apex:inputField value="{! Apprentice__c.English_Assessment__c}"/>
                <apex:inputField value="{! Apprentice__c.Date_of_Birth__c}"/>
                <apex:inputField value="{! Apprentice__c.Maths_Assessment__c}"/>
                <apex:inputField value="{! Apprentice__c.Funding_Line__c}"/>
                <apex:inputField value="{! Apprentice__c.Highest_Previous_Attainment__c}"/>
                <apex:inputField value="{! Apprentice__c.Highest_ICT_Achievement__c}"/>
                <apex:inputField value="{! Apprentice__c.Highest_English_Qual__c}"/>
                <apex:inputField value="{! Apprentice__c.Prior_Learning_Record_Attached__c}"/>
                <apex:inputField value="{! Apprentice__c.Highest_Maths_Qual__c}"/>
                <apex:inputField value="{! Apprentice__c.Learning_Difficulties__c}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
      <!--End of Education & Diagnostics-->
        
        <!--Apprenticeship Programme-->
        
        <apex:pageBlock title="Apprenticeship Programme">
            <apex:pageBlockSection columns="2" >
                <apex:inputField value="{! Apprentice__c.Apprenticeship_Title__c}"/>
                <apex:inputField value="{! Apprentice__c.Minimum_Duration__c}"/>
                <apex:inputField value="{! Apprentice__c.Apprenticeship_Pathway__c}"/>
                <apex:inputField value="{! Apprentice__c.Prefered_Duration__c}"/>
                <apex:inputField value="{! Apprentice__c.Apprenticeship_Level__c}"/>
                <apex:inputField value="{! Apprentice__c.Development_Coach__c}"/>
                <apex:inputField value="{! Apprentice__c.Apprenticeship_Type__c}"/>
                <apex:inputField value="{! Apprentice__c.Usual_College_Day__c}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
        
      <!--End of Apprenticeship Programme-->
        
      <!--Functional Skills-->
        <apex:pageBlock title="Functional Skills">
            <apex:pageBlockSection columns="2" >
                <apex:inputField value="{! Apprentice__c.Functional_Maths__c}"/>
                <apex:inputField value="{! Apprentice__c.Maths_Status__c}"/>
                <apex:inputField value="{! Apprentice__c.Functional_English__c}"/>
                <apex:inputField value="{! Apprentice__c.English_Status__c}"/> 
                <apex:inputField value="{! Apprentice__c.Functional_ICT__c}"/> 
                <apex:inputField value="{! Apprentice__c.ICT_Status__c}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
      <!--End of Functional Skills-->
        
        <!--Existing Employer Details-->
        <apex:pageBlock title="Existing Employer Details">
            <apex:pageBlockSection columns="2" >
                <apex:inputField value="{! Apprentice__c.Original_Start_Date__c}"/>
                <apex:inputField value="{! Apprentice__c.Additional_Skills_Existing_Employee__c}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
      <!--End of Existing Employer Details-->
        
        <!--End Point Assessment (EPA)-->
        <apex:pageBlock title="End Point Assessment (EPA)">
            <apex:pageBlockSection columns="2" >
                <apex:inputField value="{! Apprentice__c.Functional_Maths__c}"/>
                <apex:inputField value="{! Apprentice__c.Maths_Status__c}"/>
                <apex:inputField value="{! ComponentsObj.Qual_Aim_Text__c}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
      <!--End of End Point Assessment (EPA)-->
        
      <!--Apprenticeship Components-->
        
        <apex:pageBlock title="Apprenticeship Components">
            <apex:pageBlockSection columns="1" >
                <apex:inputField value="{! ComponentsObj.Apprenticeship_Qualifications__c}"/> 
                <apex:inputField value="{! ComponentsObj.Learning_Aim_Code__c}"/>
                <apex:inputField value="{! ComponentsObj.Level__c}"/>
                <apex:inputField value="{! ComponentsObj.Delivery_Location__c}"/>
                <apex:inputField value="{! ComponentsObj.Start_Date__c}"/>
                <apex:inputField value="{! ComponentsObj.Expected_End_date__c}"/>
                <apex:inputField value="{! ComponentsObj.Percentage_of_Aim_to_be_Delivered__c}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
      <!--End of Apprenticeship Components-->
        
      <!--Save/Cancel-->
       
        <apex:pageBlock >
        <apex:commandButton action="{!save }" value="Save" />
        </apex:pageBlock>
        
      <!--End of Save/Cancel-->
            

    </apex:form>
</apex:page>
And here is my Controller Extension 
public class myController{
public Apprentice__c ApprenticeObj{get;set;}
public Apprenticeship_Component__c ComponentsObj{get;set;}
public Programme_Area__c ProgramArea {get;set;}
public Apprenticeship_Qual__c Qual {get;set;}  
ApexPages.StandardController sc;
public myController(ApexPages.StandardController sc){ 
    this.sc = sc; 
    ApprenticeObj = new Apprentice__c(); 
    ComponentsObj = new Apprenticeship_Component__c(); 
    ProgramArea = new Programme_Area__c ();
    Qual = new Apprenticeship_Qual__c ();
}
    public void saveObjects(){
         ProgramArea.PA_Code__c = 'P12';
         insert ProgramArea;
         ApprenticeObj.Programme_area__c = ProgramArea.Id;
         ApprenticeObj.Date_of_Birth__c = date.parse('12/08/2000');
         insert ApprenticeObj;
         ComponentsObj.Apprentice__c = ApprenticeObj.Id;
         Qual.Course_Code__c = '5363hdg';
         Qual.Qual_Aim__c = 'QualAim';
         Qual.Qualification_Type__c = 'Competency';
         insert Qual;
         ComponentsObj.Apprenticeship_Qualifications__c = Qual.Id;
         insert ComponentsObj;
    }
}


Any help is much appreciated thanks
 
We have implemented NPSP in our Salesforce org. We created an Opportunity Trigger to send an email notification and create a task with a PDF attachment after an Opportunity is created. In Sandbox, when we test the trigger, it is only sending 1 email and creating 1 task, however, after deploying it to Production, it is sending 2 emails and creating 2 tasks. 

When we review the debug log, it is actually going through the After Update event before it fires the After Insert event. We verfied that there are no workflows or Process Builders fired before the After Update trigger event. Any idea why the After Update trigger is getting fired before After Insert? It is only doing this in Production, not in Sandbox.
Hi all,

How can i integrate jira and salesforce using REST API without any connectors or tools in between ?

On salesforce side we need to do remote site setings.What are the settings we need to do on JIRA side regarding salesforce.?
 
public class Risk_AnalysisExtController {
    
    public String server {get;set;}
    public String rootURL {get;set;}
    public string uId {get;set;}
    public String inputSer {get; set;} //line290
    public List<Risk_Analysis__c> listRiskAnalysis {get; set;} //All
    public List<Risk_Analysis__c> custListHistory {get; set;} //when user select customer
    public List<Risk_Analysis__c> serListHistory {get; set;} //when user select serial 
    public List<Risk_Analysis__c> serListAllExist {get; set;}
    public List<Risk_Analysis__c> serList {get; set;}
    public List<Risk_Analysis__c> serListAllNew {get; set;}
    public string paramCust {get; set;}
    public string paramSer {get; set;}
    public string paramThem {get; set;}
    public string inputComment {get; set;}
    public string paramCustText {get; set;}
    public string paramThemText {get; set;}
    public string paramBrandT {get; set;} 
    public string paramMat {get; set;}
    public string actionOpt {get; set;}
    public date inputDate {get; set;}
    public string removalReason {get; set;}
    //public Id machId {get; set;} 
    Map<string, Risk_Analysis__c> MapCheckSer = new Map<string, Risk_Analysis__c>(); 
    Map<string, Risk_Analysis__c> MapCheckExist = new Map<string, Risk_Analysis__c>(); 
    Map<string, string> MapCommentsExist = new Map<string, string>(); 
    public string outputSer {get; set;} //line292 
    //public string delCust {get; set;}
    //public string delSer {get; set;}
    
    //private list<Risk_Analysis__c> delRisk = new list<Risk_Analysis__c>(); 
    private Risk_Analysis__c delRisk ; 
    public PageReference pageRef; 
    public Map<string, string> URLParameters = ApexPages.currentPage().getParameters(); 
    
    public Id currentPageId; 
    
    List<riskWrapper> rList = new List<riskWrapper>();
    List<Risk_Analysis__c> selectedRecords = new List<Risk_Analysis__c>();
    public List<Risk_Analysis__c> delRecords = new List<Risk_Analysis__c>();
    public list<riskWrapper> riskList = new List<riskWrapper>();// {get; set;} 
    
    
    
    
    public Risk_AnalysisExtController(ApexPages.StandardController stdController) {
        string trustedTicket ='';
        //dashboard url with trusted ticket
        server = 'https://test.tableaureporting.test.com';
        if (Functions.isProduction()) server = 'https://tableaureporting.test.com';
        
        //currently loggedin user 
        User u = [select name, Alias, CommunityNickname, FederationIdentifier, Domain_Credential__c, SAP_Partner_Number__c from user where Id = :UserInfo.getUserId() limit 1]; //added Domain_Credential__c
        string userid = ''; 
        if(vUser(u.id).equals('Correct'))
            userid =u.Domain_Credential__c.toLowerCase();
        
        if(u.SAP_Partner_Number__c!=null)uId = String.valueof('000'+u.SAP_Partner_Number__c); 
      //  system.debug('uId'+uId); 
        
      //  system.debug('userid = ' +userid);
      //  system.debug('server = '+ server);
        //retrieve trusted ticket
        trustedTicket = getTicket(userid, 'Sales_Ops', server);
        rootURL = server+ '/trusted/'+trustedTicket;
        system.debug('rootURL = '+rootURL);
        system.debug('trustedTicket = '+ trustedTicket);
        
        //buffer
        serListHistory = [Select Id, Customer__c, Comments__c, Serial_Number__c, Theme__c, End_of_Life_Date__c, Action__c, 
                          Removal_Reason__c, Customer_Name__c, Brand_Name__c, Theme_Name__c, Cabinet__c
                          from Risk_Analysis__c where  Serial_Number__c=: paramSer];   
        serListAllExist = [Select Id, Customer__c, Comments__c, Serial_Number__c, Theme__c, End_of_Life_Date__c, Action__c, 
                           Removal_Reason__c, Customer_Name__c, Brand_Name__c, Theme_Name__c, Cabinet__c
                           from Risk_Analysis__c where  Serial_Number__c=: paramSer];  
        serListAllNew = [Select Id, Customer__c, Comments__c, Serial_Number__c, Theme__c, End_of_Life_Date__c, Action__c, 
                         Removal_Reason__c, Customer_Name__c, Brand_Name__c, Theme_Name__c, Cabinet__c
                         from Risk_Analysis__c where  Serial_Number__c=: paramSer]; 
        
        listRiskAnalysis = [Select Id, Customer__c, Comments__c, Serial_Number__c, Theme__c, End_of_Life_Date__c, Action__c, 
                            Removal_Reason__c, Customer_Name__c, Brand_Name__c, Theme_Name__c, Cabinet__c
                            from Risk_Analysis__c]; 
       
        
        
        
        
        /*if(paramCust!= null && paramCust.isNumeric() && (paramSer == null || paramSer == '')) {
            
            String CustNumTemp; 
            CustNumTemp = paramCust.right(7);
            custListHistory = [Select Id, Customer__c, Comments__c, Serial_Number__c, Theme__c, End_of_Life_Date__c, Action__c, 
                               Removal_Reason__c, Customer_Name__c, Brand_Name__c, Theme_Name__c, Cabinet__c, Delete__c 
                               from Risk_Analysis__c where Customer__c =: CustNumTemp];
            
        }
        
        MapCommentsExist.put(paramSer, inputComment);*/
               
    
    }
    
    
      
        public class riskWrapper
    {
        public Risk_Analysis__c risk{get; set;}
        public Boolean selected {get; set;}
        public RiskWrapper(Risk_Analysis__c r)
        {
            risk = r;
            selected = false;
        }
    }

So here's a section of of a class i have to write a test class for. They want 90% coverage, I'm at 87%, lol woe is me. 

My one problem is the wrapper class, through the rest of the code and this snippet it's the one thing i can't seem to get coverage one.... I've tried 
 
class.wrapper wrap = new class.wrapper();
But i cant seem to figure that one out....i tried to insert and also map<string,string> mapvr = new map<string,string(); refer to the class set var; list<apexpages.message>msgs = apexpages.getmessages(); then mpvr.put(field, data) then trying to force the wrapper by referencing to it directly..

I only need coverage not functionality at this point because that's all been tested and the rest of my test class covers 87% of the functionallity.