• Kim
  • NEWBIE
  • 24 Points
  • Member since 2016
  • LogMeIn

  • Chatter
    Feed
  • 1
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 5
    Replies
Just getting more practice with formulas but have run into an obstacle. Hopefully I'm overthinking it, but I'm writing a throw away formula:

IF( AnnualRevenue >= 1000000, NumberOfEmployees, " ???  ")

The goal is to throw an error message telling the user if the "AnnualRevenue" is greater than or equal to one million, then the "NumberOfEmployees" field is mandatory, else do nothing. What value do I need to enter in the "false" field? I've tried using "null" however there needs to be an actual value. Is using an "IF" statement the wrong route to take for this goal?

Any assistance is more than welcome. Thanks in adnvacned!!
Hello,

Has anyone been able to successfully show picklist values based on record type using lightning components? We have 4 record types and for some reason all record types is defaulting to the RSO record type picklist values.

This is what I have so far and it is not displaying the correct picklist values based on the record type.

Parent Component:
<aura:component controller="BusinessRequest_LightningController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,forceCommunity:availableForAllPageTypes" access="global">
    
    <!--Initialization-->
    
    <aura:handler name="init" value="{!this}" action="{!c.fetchListOfRecordTypes}"/>
    
    
    <!--Attribute Setup-->
    <aura:attribute name="isOpen" type="Boolean" default="false"/> 
    <aura:attribute name="simpleRecord" type="Object"/> 
    <aura:attribute name="record" type="Object"/>
    
    <!--Record Type Attributes-->
    <aura:attribute name="recordTypeMap" type="Map"/>   
    <aura:attribute name="recordTypeChoice" type="String" default="-- None --"/>
    <aura:attribute name="recordTypeId" type="Id"/>   
    
    <!--Field Attributes-->
    <aura:attribute name="category" type="String"/>  
    <aura:attribute name="subcategory" type="String"/>    
    <aura:attribute name="status" type="String"/>      
    <aura:attribute name="subject" type="String"/>      
    <aura:attribute name="description" type="String"/>      
    <aura:attribute name="steps" type="String"/>
    <aura:attribute name="email" type="String"/> 
    <aura:attribute name="date" type="Date"/>
    <aura:attribute name="comments" type="String"/>
    
    
    <!--Object Field Retrieval-->
    
    <force:recordData aura:id="objectFields"
                      recordId="{!v.recordId}" 
                      layoutType="FULL"
                      targetRecord="{!v.record}"
                      targetFields="{!v.simpleRecord}"
                      mode="VIEW"/>
    
    <!-- Title -->
    
    <div class="slds-grid">
        <div class="slds-col slds-has-flexi-truncate">
            <p class="slds-text-heading--large">Business Request</p>
            <div class="slds-grid" style="background-color: #F4F6F9;">
                <div class="slds-grid slds-type-focus slds-no-space">
                    <h1 class="slds-text-heading--medium slds-truncate" style="font-weight: bold;" title="Business Request Quick Create">Quick Create</h1><br/><br/>
                </div>
            </div>
        </div>
    </div>
    
    <!--Main Form--> 
    <form id="mainForm" class="slds-form--stacked">
        <aura:if isTrue="{!v.isOpen}"> 
            
            <!--Record Type Selection-->
            <div class="slds-form-element slds-is-required">
                <div class="slds-form-element__control" style="width: 175px;">
                    <ui:inputSelect aura:id="recordTypes" 
                                    class="slds-input"
                                    labelClass="slds-form-element__label"               
                                    value="{!v.recordTypeChoice}"
                                    required="true"
                                    change="{!c.getRecordTypeId}"/><br/><br/>
                </div>
            </div>
    
            <!--RSO Request-->
            <aura:if isTrue="{!v.recordTypeChoice == 'RSO'}">
                <c:BusinessRequest_RSO recordTypeId="{!v.recordTypeId}"
                                       recordTypeMap="{!v.recordTypeMap}"
                                       category="{!v.category}"
                                       comments="{!v.comments}"
                                       email="{!v.email}"
                                       date="{!v.date}"/> 			  
                
            </aura:if>
            
            <!--Legal Request-->
            <aura:if isTrue="{!v.recordTypeChoice == 'Legal'}">
                <div aura:id="legalRecord" class="slds-show">
                    <c:BusinessRequest_LegalRequest />			  
                </div>
            </aura:if>
            
            
            <!--Commision Dispute--> 
            
            <!--Sales Ops-->		
            <aura:if isTrue="{!v.recordTypeChoice == 'Sales Operations'}">  
                <c:BusinessRequest_SalesOps recordTypeId="{!v.recordTypeId}"
                                            category="{!v.category}"
                                            subcategory="{!v.subcategory}"
                                            status="{!v.status}"
                                            subject="{!v.subject}"
                                            description="{!v.description}"
                                            steps="{!v.steps}"/>
            </aura:if>
            
            
        </aura:if>
    </form>
    
    
</aura:component>

RSO Child Component:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,forceCommunity:availableForAllPageTypes" access="global">
    
    <!--Attribute Setup-->
    <aura:attribute name="showRecordType" type="Boolean" default="false"/>
    <aura:attribute name="recordTypeId" type="Id"/> 
    <aura:attribute name="recordTypeMap" type="Map"/>
    <aura:attribute name="email" type="String"/>
    <aura:attribute name="date" type="Date"/>
    <aura:attribute name="category" type="String"/>
    <aura:attribute name="comments" type="String"/>
    
    <!--RSO Business Request Form--> 
    <div aura:id="rsoComponent">
      
                <!--Lightning Input Field-->
        
                <lightning:recordEditForm aura:id="rsoRecordCreate"
                                          recordTypeId="{!recordTypeId}"
                                          objectApiName="Business_Request__c">
                    <lightning:inputField aura:id="email" fieldName="LMI_Email__c"/>
                    <lightning:inputField aura:id="date" fieldName="Request_Date__c"/>
                    <lightning:inputField aura:id="category" fieldName="Category__c"/>
                    <lightning:inputField aura:id="subcategory" fieldName="Sub_category__c"/>
                    <lightning:inputField aura:id="comments" fieldName="Comments__c"/>
                </lightning:recordEditForm>
           
    </div>
    
    
    <!--Record Type Selection--> 
    <aura:if isTrue="{!v.showRecordType}"> 
        <c:BusinessRequest_QuickCreate />
    </aura:if>    
    
</aura:component>

Sales Ops Child Component:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,forceCommunity:availableForAllPageTypes" access="global">
    
    <!--Attribute Setup-->
    
    <aura:attribute name="recordTypeId" type="Id"/> 
    <aura:attribute name="recordTypeMap" type="Map"/>    
    <aura:attribute name="category" type="String"/>    
    <aura:attribute name="subcategory" type="String"/>     
    <aura:attribute name="status" type="String"/>      
    <aura:attribute name="subject" type="String"/>      
    <aura:attribute name="description" type="String"/>      
    <aura:attribute name="steps" type="String"/>
    
    <!-- Sales Operations Business Requests Form --> 
    
    <div aura:id="salesOpsComponent"> 
        <!-- Input Fields -->
        <lightning:recordEditForm aura:id="salesOpsRecordCreate"
                                      recordTypeId="{!recordTypeId}"
                                      objectApiName="Business_Request__c">
            <div class="slds-form" role="list" style="width:700px;">
                <div class="slds-grid slds-gutters_small">
                    <div class="slds-col slds-has-flexi-truncate" role="listitem">
                        <div class="slds-form-element slds-form-element_edit slds-hint-parent">
                            <div class="slds-form-element__control">
                                <lightning:inputField aura:id="category" fieldName="Category__c"/>
                            </div>
                        </div>
                    </div>
                    <div class="slds-col slds-has-flexi-truncate" role="listitem">
                        <div class="slds-form-element slds-form-element_edit slds-hint-parent">
                            <div class="slds-form-element__control">
                                <lightning:inputField aura:id="subcategory" fieldName="Sub_category__c" value="{!v.subcategory}"/><br/><br/>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="slds-grid slds-gutters_small" style="width: 360px;">                
                    <div class="slds-col slds-has-flexi-truncate" role="listitem">
                        <div class="slds-form-element slds-form-element_edit slds-hint-parent">
                            <div class="slds-form-element__control">
                                <lightning:inputField aura:id="status" fieldName="Status__c" value="{!v.status}"/><br/><br/>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="slds-grid slds-gutters_small">
                    <div class="slds-col slds-has-flexi-truncate" role="listitem">
                        <div class="slds-form-element slds-form-element_edit slds-hint-parent">
                            <div class="slds-form-element__control">
                                <lightning:inputField aura:id="subject" fieldName="Subject__c" value="{!v.subject}"/><br/><br/>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="slds-grid slds-gutters_small">
                    <div class="slds-col slds-has-flexi-truncate" role="listitem">
                        <div class="slds-form-element slds-form-element_edit slds-hint-parent">
                            <div class="slds-form-element__control">
                                <lightning:inputField aura:id="description" fieldName="Description__c" value="{!v.description}"/>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </lightning:recordEditForm>   
    </div>
    <!-- End Sales Operations Business Requests Form --> 
</aura:component>


 
  • May 18, 2018
  • Like
  • 0
Hello,

I need a some feedback/guidance with nested maps.
Business request: Pull a list of records from our custom object "RAT" and do a comparison to check for the "Role" & "LOB" of each rat record.  
I have constructed a nested map where my 1st key = LOB, and my 2nd key = Role, and found that my containskey check isn't finding correct Rat record with the correct 1st key (LOB), but it matches my 2nd key (Role) value. Any idea why it is passing through the if check below,
if (ratMap.containsKey('Access')) {
even though the LOB value for that rat was not 'Access'?

 
Map<String, Map<String, List<Account_Team_Role__c>>> ratMap = new Map<String, Map<String, List<Account_Team_Role__c>>> (); //1st key = LOB, 2nd key = Role
Map<String, List<Account_Team_Role__c>> ratRoleMap = new Map<String, List<Account_Team_Role__c>> (); //Key = Role 
Map<String, List<Account_Team_Role__c>> intlRat = new Map<String, List<Account_Team_Role__c>> (); //Key = LOB
Id automationUserId = '00530000001pyWZAAY';
Id returnNARatId;


		List<Account_Team_Role__c> ratQuery = [SELECT Id, Role__c, LOB__c, User__c, Product_Specialty__c, Active__c, Active_User__c FROM Account_Team_Role__c
		                                       WHERE Active_User__c = True AND Active__c = True AND Account__c = :request.AccountId];

		for (Account_Team_Role__c r : ratQuery) {

			if (request.Market == 'NA') {

				if (ratMap.containsKey(r.LOB__c)) {
					
					ratRoleMap = ratMap.get(r.LOB__c);
					
					if (ratRoleMap.containsKey(r.Role__c)) {
						ratRoleMap.get(r.Role__c).add(r);
						
					} else {
						ratRoleMap.put(r.Role__c, new List<Account_Team_Role__c> { r });
						
					}
					
				}
				//If the ratMap doesn't contain the LOB key 
				else {
					//Map<String, List<Account_Team_Role__c>> ratRoleMap = new Map<String, List<Account_Team_Role__c>> ();
					ratRoleMap.put(r.Role__c, new List<Account_Team_Role__c> { r });
					ratMap.put(r.LOB__c, ratRoleMap);
					
				}
			} else if (request.Market != 'NA') {
				System.debug('Getting this FAR 0 --> ' + ratMap);
				if (intlRat.containsKey(r.LOB__c)) {
					intlRat.get(r.LOB__c).add(r);
				} else {
					intlRat.put(r.LOB__c, new List<Account_Team_Role__c> { r });
				}
			}
		}

		
   
		if (request.Market == 'NA') {

			if (ratMap.containsKey('Access')) {
				
				if (ratMap.get('Access').containsKey('Majors')) {
					
					returnNARatId = ratMap.get('Access').get('Majors') [0].User__c;

				} else if (ratMap.get('Access').containsKey('BDR')) {
					
					returnNARatId = ratMap.get('Access').get('BDR') [0].User__c;

				} else if (ratMap.get('Access').containsKey('Hunter')) {

					if (ratMap.get('Access').get('Hunter') [0].Product_Specialty__c == request.OppLProduct) {
						returnNARatId = ratMap.get('Access').get('Hunter') [0].User__c;
					}

				} else if (ratMap.get('Access').containsKey('Account Manager')) {
					if (ratMap.get('Access').get('Account Manager') [0].Product_Specialty__c == request.OppLProduct) {
						returnNARatId = ratMap.get('Access').get('Account Manager') [0].User__c;
					}

				} else {
					returnNARatId = automationUserId;
				}

 
  • March 09, 2018
  • Like
  • 0
Hello,

New at development and was wondering if anyone has come across the scenario where long textbox field contains existing values, and additional info needs to be appended to that existing long textbox without overwriting existing values? Is it possible to populate the old values + add the new values without having to create a new field to store the new values temporarily and update the long textbox field with the new values from the temp field?

Thanks!

Thanks!
  • February 09, 2018
  • Like
  • 0
Hello,

I'm not sure why the trigger is not triggering the Case assignment rules. I've checked other posts and have tried to requery my list and I'm still unable to get the Case Assignment Rule to work. 
 
public class Case_RunAssignmentRule {

	public static void runCaseAssignmentRules(List<Case> caseList) {

		List<Case> caseToUpdate = new List<Case> ();
		Id caseInboundRecordType = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Inbound Case').getRecordTypeId();

		for (Case c : caseList) {
			if (c.RecordTypeId == caseInboundRecordType) {
				caseToUpdate.add(c);
				System.debug('CaseID --> ' + caseToUpdate);
			}

		}

		if (caseToUpdate.size() > 0) {
			//List<Case> caseToRunAssignment = [SELECT Id, OwnerId FROM Case WHERE Id IN :caseToUpdate];


			Database.DMLOptions dmo = new Database.DMLOptions();
			dmo.assignmentRuleHeader.useDefaultRule = true;
			System.debug('DMO --> ' + dmo);

			for (Case caseL : caseToUpdate) {
				caseL.setOptions(dmo);
				System.debug('caseOwner --> ' + caseL.OwnerId);
				System.debug('caseId --> ' + caseL);
			}

			//insert caseToUpdate;

		}
	}
}
@isTest
public class Case_RunAssignmentRuleTest {

	@testSetup static void setupTest() {
		List<TriggerController__c> tc = new List<TriggerController__c> {
			new TriggerController__c(Name = 'Case', Disabled__c = false)
		};
	}

	static testmethod void newCaseInsert() {
        
		List<Case> newCases = new List<Case> ();
		for (Integer i = 0; i<5; i++) {
			Case c = new Case();
			c.Subject = 'InboundCaseForCAR' + i;
			c.Product__c = 'G2M';
			c.Reason_Category__c = 'Admin Change';
			c.Case_Category__c = 'Contract Services';
			c.Status = 'New';
            c.RecordTypeId = '01213000001ZUeG'; 
			newCases.add(c);
		}

		test.startTest();
		insert(newCases);

		Id currentUserId = UserInfo.getUserId();

		List<Case> returnCaseList = [SELECT Id, OwnerId, Subject FROM Case WHERE Id IN :newCases];
		for (Case c : returnCaseList) {
			System.assertNotEquals(currentUserId, c.OwnerId);
			System.assertEquals(5, returnCaseList.size());
		}
		test.stopTest();
	}
}


 
  • December 07, 2017
  • Like
  • 0
Hello, 

I have a trigger on FeedComment that creates an Internal Request ticket (custom object) if a specific chattergroup was added on the comment. Does anyone know how I can access the ChatterGroup @IRTicket without having to use SeeAllData = true?

Class: 
public class InternalRequest_CreateFromChatterComment {

    public static void createNewInternalRequest(List<FeedComment> chatterComment){

		List<FeedComment> lFeedComment = new List<FeedComment>(); 
        List<Id> lFeedItem = new List<Id>(); 
        Map<Id,String> mfeedItemBody = new Map<Id,String>(); 
		Map<Id,Id> mpostUserId = new Map<Id,Id>();
		List<Ops_Priority_List__c> newIRtoInsert = new List<Ops_Priority_List__c>(); 
		Id internalRequestQuestionRecordTypeId = Schema.SObjectType.Ops_Priority_List__c.getRecordTypeInfosByName().get('Question').getRecordTypeId(); 

			List<User> lUser = [SELECT Id FROM User WHERE ProfileId = '00ea00000021duy']; //Checks if the user is an admin 
			Set<Id> userIds = new Set<Id>(new Map<Id, User>(lUser).keyset()); 

			Id cgroupId = [SELECT Id, Name FROM CollaborationGroup WHERE Name = 'IRTicket'].Id; //Stores chatterGroupId ca
    
        for(FeedComment c : chatterComment){
			
			if((c.ParentId ==  cgroupId && userIds.contains(c.CreatedById)) || (c.CommentBody.contains('@IRTicket') && userIds.contains(c.CreatedById))){
				lFeedComment.add(c); //List of all ChatterComments
                lFeedItem.add(c.FeedItemId); //List of all ChatterFeedItems 
				mpostUserId.put(c.Id,c.CreatedById);
			}
			System.debug('lFeedComment -->' + lFeedComment); 
			System.debug('mpostUserId -->' + mpostUserId); 
			System.debug('InsertedbyId -->' + c.CreatedById); 
		}

		if(lFeedComment.size()>0){
			System.debug('lFeedComment size --> ' + lFeedComment.size()); 
            
			List<FeedItem> feedItemList = [SELECT Body,ParentId FROM FeedItem WHERE Id =:lFeedItem]; 
           
            for(FeedItem f : feedItemList){
                mfeedItemBody.put(f.Id,f.Body); 
            }
			for(FeedComment cg : lFeedComment){
                lFeedItem.add(cg.FeedItemId); 
				
					Ops_Priority_List__c i = new Ops_Priority_List__c(
						OwnerId = mpostUserId.get(cg.Id),  
						Description__c = mfeedItemBody.get(cg.FeedItemId).stripHtmlTags() + ' ' + cg.CommentBody + ' ' + URL.getSalesforceBaseURL().toExternalForm() + '/'+
                        cg.ParentId + '?fld=' +cg.FeedItemId,   
					 	Name = 'Questions from Chatter',   
						Status__c = 'New', 
						RecordTypeId = internalRequestQuestionRecordTypeId); 

						newIRtoInsert.add(i); 
			}
			System.debug('newIRtoInsert = ' + newIRtoInsert); 
		}
		if(!newIRtoInsert.isEmpty()){
			try{
				database.insert(newIRtoInsert,false); 
			} catch (DmlException e){
				System.debug('The following exception has occured: ' + e.getMessage()); 
			}


			System.debug('newIRinserted = '+ !newIRtoInsert.isEmpty()); 
		}
	}
}

TestClass:
@isTest
public class InternalRequest_CreateFromChatterCTest {
    
    @testSetup static void setup(){
        List<TriggerController__c> tc = new List<TriggerController__c>{
            new TriggerController__c(Name='Lead',Disabled__c=false)
        }; 
            insert tc;
        
        User u = new User(
            LastName = 'Newuser', 
            Alias = 'newu', 
            Email = 'newuser@lmitest.com', 
            Username = 'newuser@lmitest.com.kdy', 
            CommunityNickname = 'newuser', 
            ProfileId = UserInfo.getProfileId(),
            TimeZoneSidKey = 'America/New_York', 
            LocaleSidKey = 'en_US', 
            EmailEncodingKey = 'UTF-8', 
            LanguageLocaleKey = 'en_US'
        ); 
        insert u; 
        
        
        Lead l = new Lead(
            FirstName = 'Firsttest', 
            LastName = 'Samplelead', 
            Email = 'firstsample@Samplelead.com', 
            CountryCode = 'US',
            Company = 'TestLeadCompany'
        ); 
        insert l; 
        
        
        FeedItem lPost = new FeedItem(
            ParentId = l.Id, 
            Body = 'Chatterpost from the lead'
        ); 
        insert lPost; 
        
    }
    
    static testMethod void leadChatterComment(){
      
        User u = [SELECT Id, EMAIL FROM User WHERE Username = 'newuser@lmitest.com.kdy' LIMIT 1]; 
        System.debug('u--->' + u); 
        Lead le = [SELECT Id FROM Lead WHERE Email = 'firstsample@Samplelead.com' LIMIT 1]; 
        System.debug('le-->' + le); 
        FeedItem f = [SELECT Id,CreatedById,ParentId FROM FeedItem WHERE ParentId =: le.Id LIMIT 1]; 
        System.debug('f-->' + f); 
        
        FeedComment lComment = new FeedComment(
            CommentBody = '@IRTicket - create this new IR', 
            FeedItemId = f.Id
        ); 
        test.startTest(); 
        insert lComment; 
        System.debug('lComment-->' + lComment); 
        test.stopTest(); 
        
        Ops_Priority_List__c iR = [SELECT Id,Name,OwnerId FROM Ops_Priority_List__c WHERE OwnerId =: f.CreatedById LIMIT 1]; 
        System.assertEquals('Questions from Chatter', iR.Name); 
        System.assertEquals(f.CreatedById,iR.OwnerId); 
        
        
    }
}

 
  • October 30, 2017
  • Like
  • 0
Hello, 

New to writing trigger so I'm unsure why I'm getting the Id is not specified error. Goal is if an existing user record's Channel OR LOB field  is updated then, it should look for existing User History record and update the Role_End_Date__c and create a new history record with for that same user with the Role_Start_Date__c as today. 
 
public class UserHistory_CreateUpdateFromUser  {

	public static void findUser(List<User> newUsers, Map<Id,User> oldUsers, Boolean isInsert){

		List<User> newUserList = new List<User>(); 
		List<User> lOBChannelList = new List<User>();
		List<User> isActiveList = new List<User>(); 
		List<User> uManagerLOBChannelList = new List<User>();
        List<User> uManagerList = new List<User>(); 
		Map<Id,List<User>> reasonForUpdatingUser = new Map<Id,List<User>>(); 
			
       	for(User u : newUsers){
            //New user && Channel != Non Sales  
            if(u.Channel__c != 'Non Sales'){
                if(isInsert){ 
       				newUserList.add(u); 
       				System.debug('newUserList: '+ newUserList); 
       			}
                //Existing user && Channel || LOB is changed 
       			else if(!isInsert && (u.Channel__c != oldUsers.get(u.Id).Channel__c || u.LOB_Focus__c != oldUsers.get(u.Id).LOB_Focus__c)) {
       				lOBChannelList.add(u); 
       				System.debug('lOBChannelList: '+ lOBChannelList); 
       			}
       			//Existing user && deactived 
       			else if(!isInsert && u.IsActive != oldUsers.get(u.Id).IsActive){
       				isActiveList.add(u); 
       				System.debug('isActiveList: '+ isActiveList);
                }
                //Existing user && Manager is changed && Channel || LOB is changed 
       			else if(!isInsert && u.ManagerId != oldUsers.get(u.Id).ManagerId &&
                        (u.Channel__c != oldUsers.get(u.Id).Channel__c || u.LOB_Focus__c != oldUsers.get(u.Id).LOB_Focus__c)){
       				uManagerLOBChannelList.add(u); 
       				System.debug('uManagerLOBChannelList: '+ uManagerLOBChannelList);
       			}
       			//Existing user && Manager is changed 
                else if(!isInsert && u.ManagerId != oldUsers.get(u.Id).ManagerId){
                    uManagerList.add(u); 
                    System.debug('uManagerList: '+ uManagerList);
                }
            }     
       	}

       	if(newUserList.size()>0){
       		newUser(newUserList);
       	}	

       	if(lOBChannelList.size()>0){
       		lOBChannelUpdate(lOBChannelList); 
       	}

       	if(isActiveList.size()>0){
       		userisActiveUpdate(isActiveList); 
       	}

       	if(uManagerList.size()>0){
       		managerUpdateOnly(uManagerList); 
       	}

       	if(uManagerLOBChannelList.size()>0){
       		managerLOBChannelUpdate(uManagerLOBChannelList); 
       	}
       
	}

	public static void lOBChannelUpdate(List<User> lOBChannelList){
		//Find existing User History record and update end date fields 
		//Create new user history record and update fields based on user changes 

		List<Id> userIds = new List<Id>(); 
		List<User_History__c> existingUHtoUpdate = new List<User_History__c>(); 
		List<User_History__c> newUHtoInsert = new List<User_History__c>(); 

		for(User u : lOBChannelList){
			userIds.add(u.Id); 
		}
		System.debug('userIds: '+ userIds);
		System.debug('lOBChannelList: '+ lOBChannelList);

		if(userIds.size()>0){
			List<User_History__c> eUH = [SELECT Id, User__C, Role_End_Date__c, Manager_End_Date__c FROM User_History__c
											WHERE User__c =:userIds]; 
            System.debug('eUH' + eUH); 

			for(User_History__c uH : eUH){

                User_History__c existingUH = new User_History__c(); 
                
                if(uH.Role_End_Date__c == NULL){
					existingUH.Role_End_Date__c = Date.today(); 
					existingUH.Id = uH.Id;
                }
                else if(uH.Manager_End_Date__c == NULL){
					existingUH.Manager_End_Date__c = Date.today(); 
					existingUH.Id = uH.Id;
                }
                else if(uH.Role_End_Date__c == NULL && uH.Manager_End_Date__c == NULL){
                    existingUH.Role_End_Date__c = Date.today(); 
                    existingUH.Manager_End_Date__c = Date.today(); 
                    existingUH.Id = uH.Id;
                }
				existingUHtoUpdate.add(existingUH); 
			}
			System.debug('existingUHtoUpdate: '+ existingUHtoUpdate);

			for(User u1 : lOBChannelList){
                
				User_History__c newUH = new User_History__c(
				User__c = u1.Id, 
				Channel__c = u1.Channel__c,  
				LOB_Focus__c = u1.LOB_Focus__c,  
				Role_Start_Date__c = Date.today(), 
				Manager_Start_Date__c = Date.today()
			); 
				newUHtoInsert.add(newUH); 
				
			}	
			System.debug('newUHtoInsert: '+ newUHtoInsert);
		}

		if(!existingUHtoUpdate.isempty()){
			Database.update(existingUHtoUpdate); 
		}
		System.debug('Databaseupdate existingUHtoUpdate: ' + existingUHtoUpdate); 

		if(!newUHtoInsert.isempty()){
			Database.insert(newUHtoInsert);
		}

	}
I've checked on the debug log that it is finding the Id of the existing User History record when I do the query and added it on the list 'eUH' and looped through that list. 

 
  • October 17, 2017
  • Like
  • 1
Hello, 

I'm receiving an error message System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, FeedItem: execution of AfterInsert caused by: System.QueryException: List has no rows for assignment to SObject. Class.InternalRequest_CreateNew.createNewIR: line 11, column 1
Trigger.FeedItem: line 13, column 1: []. This error occurs when I run my test class. 

I'm unsure why I'm getting this error since Class.InternalRequest_CreateNew.createNewIR: line 11, column 1 line is querying an Id that exist in the sandbox which is this line of code 
Id  cgroupId = [SELECT Id, Name FROM CollaborationGroup WHERE Name =: 'IRTicket'].Id;


 
Here's the trigger class. 

public class InternalRequest_CreateNew {

	public static void createNewIR(List<FeedItem> chatterpost){

		List<FeedItem> lGroupFeed = new List<FeedItem>(); 
		Map<Id,Id> mpostUserId = new Map<Id,Id>();
		Set<Id> sUserId = new Set<Id>(); 
		List<Ops_Priority_List__c> newIRtoInsert = new List<Ops_Priority_List__c>(); 
		Id internalRequestQuestionRecordTypeId = Schema.SObjectType.Ops_Priority_List__c.getRecordTypeInfosByName().get('Question').getRecordTypeId(); 

		Id  cgroupId = [SELECT Id, Name FROM CollaborationGroup WHERE Name =: 'IRTicket'].Id; 

		System.debug('cgroupId =' + cgroupId); 

        List<User> lUser = [SELECT Id FROM User WHERE ProfileId = '00ea00000021duy']; 
        Set<Id> userIds = new Set<Id>(new Map<Id, User>(lUser).keyset()); 
 	 
		for(FeedItem c : chatterpost){
			if((c.ParentId == cgroupId && userIds.contains(c.CreatedById)) || (c.Body.contains('@IRTicket') && userIds.contains(c.CreatedById))){
				lGroupFeed.add(c); 
				sUserId.add(c.CreatedById); 
				mpostUserId.put(c.Id,c.CreatedById);
			}
			System.debug('lGroupFeed =' + lGroupFeed); 
			System.debug('mpostUserId =' + mpostUserId); 
			System.debug('InsertedbyId =' + c.CreatedById); 
		}

		if(lGroupFeed.size()>0){
			System.debug('lGroupFeed size = ' + lGroupFeed.size()); 

			for(FeedItem cg : lGroupFeed){
				
					Ops_Priority_List__c i = new Ops_Priority_List__c(
						OwnerId = mpostUserId.get(cg.Id),  
						Description__c = cg.Body.stripHtmlTags() + '   ' + URL.getSalesforceBaseURL().toExternalForm() + '/_ui/core/chatter/groups/GroupProfilePage?g=' + cgroupId + '&fld=' +cg.Id,   
					 	Name = 'Questions from Chatter',   
						Status__c = 'New', 
						RecordTypeId = internalRequestQuestionRecordTypeId); 
						newIRtoInsert.add(i); 
			}
			System.debug('newIRtoInsert = ' + newIRtoInsert); 
		}
		if(!newIRtoInsert.isEmpty()){
			try{
				database.insert(newIRtoInsert,false); 
			} catch(DMLException e){
				System.debug('The following exception has occured: '+ e.getMessage()); 
			}	
			

			System.debug('newIRinserted = '+ !newIRtoInsert.isEmpty()); 
		}
	}
}
 
Here's the test class

@isTest
private class InternalRequest_CreateNewTest  {

	@testSetup static void setup(){

		List<TriggerController__c> tc = new List<TriggerController__c>{
			new TriggerController__c(Name = 'Lead',Disabled__c = false)
		}; 

		insert tc; 

		/*CollaborationGroup cgroup = new CollaborationGroup(
			CollaborationType = 'Public', 
			Name = 'IRTicket', 
			OwnerId = '0051300000CLFco' 
		); 
		insert cgroup;*/ 

		User admin = new User(
			LastName = 'Adminuser', 
			Alias = 'admin', 
			Email = 'adminuser@logmein.com', 
			Username = 'adminuser@logmein.com.kdy', 
			CommunityNickname = 'adminuser', 
			ProfileId = '00ea00000021duy',
            TimeZoneSidKey = 'America/New_York', 
			LocaleSidKey = 'en_US', 
			EmailEncodingKey = 'UTF-8', 
			LanguageLocaleKey = 'en_US'
		); 
		insert admin; 

		User sales = new User(
			LastName = 'Salesuser', 
			Alias = 'sales', 
			Email = 'salesuser@logmein.com', 
			Username = 'salesuser@logmein.com.kdy', 
			CommunityNickname = 'salesuser', 
			ProfileId = '00e30000001euS4',
			TimeZoneSidKey = 'America/New_York', 
			LocaleSidKey = 'en_US', 
			EmailEncodingKey = 'UTF-8', 
			LanguageLocaleKey = 'en_US'
		);
		insert sales; 

		Lead l = new Lead(
			FirstName = 'Firsttest', 
			LastName = 'Samplelead', 
			Email = 'firstsample@Samplelead.com', 
			CountryCode = 'US',
			Company = 'TestLeadCompany'
		); 
		insert l; 

		FeedItem lPost = new FeedItem(
			ParentId = l.Id, 
			Body = '@IRTicket, Chatterpost from the lead'
		); 
		insert lPost; 

		FeedItem gPost = new FeedItem(
			ParentId = '0F90q0000004Ecc', 
			Body = 'Chatterpost from chattergroup'
		); 
		insert gPost; 

		}

	//Covers scenario where Admin creates chatter post on lead
	static testMethod void adminLeadChatterPost(){

		test.startTest(); 
		User adm = [SELECT Id, EMAIL FROM User WHERE Email = 'adminuser@logmein.com' LIMIT 1]; 
		Lead le = [SELECT Id, Email FROM Lead WHERE Email = 'firstsample@Samplelead.com' LIMIT 1]; 
		FeedItem f = [SELECT Id, ParentId, CreatedByID FROM FeedItem WHERE ParentId =: le.Id LIMIT 1]; 

		Ops_Priority_List__c i = [SELECT Id, Description__c, OwnerId, Name FROM Ops_Priority_List__c WHERE OwnerId =: f.CreatedById LIMIT 1];
		test.stopTest(); 

		System.assertEquals('Questions from Chatter',i.Name); 
	}

	//Covers scenario where Admin creates chatter post directly on chatter group 
	static testMethod void adminGroupChatterPost(){

		test.startTest(); 
		User adm = [SELECT Id, EMAIL FROM User WHERE Email = 'adminuser@logmein.com' LIMIT 1]; 
		FeedItem f = [SELECT Id, ParentId, CreatedByID FROM FeedItem WHERE ParentId =: '0F90q0000004Ecc' LIMIT 1]; 

		Ops_Priority_List__c i = [SELECT Id, Description__c, OwnerId, Name FROM Ops_Priority_List__c WHERE OwnerId =: f.CreatedById LIMIT 1];
		test.stopTest(); 

		System.assertEquals('Questions from Chatter',i.Name); 
	}
}

Thank you 
  • October 02, 2017
  • Like
  • 0
Hello,

I'm trying to write an if statement logic on  the action value of a command button on VF page. I'm not sure if this is possible, what the right syntax is because I'm still getting an error. The goal is to validate if a user fills out specific fields on the vf page where an error pops up to tell them they are missing specific fields and it should block users from saving the record. The current behavior, error window pops up, but it still allows them to save. Any insight is appreciated. 
 
Javascript: 


<script type="text/javascript">
    	function validateType() {
            var error = FALSE; 
            var valType ='{!Opportunity.Initial_Follow_Up_Type__c}';
            var valDate ='{!Opportunity.Follow_Up_Date__c}';
            var valTime ='{!Opportunity.Appointment_Time__c}';
            var valTimeofDay ='{!Opportunity.Follow_Up_Time_of_Day__c}';
           if((valType=="Email" || valType=="Phone") && valDate=="" && valTime=="" && error==TRUE){
        alert("If Initial Follow Up Type = Phone/Email, Follow Up Date is Required, Follow Up Time of Day is Required, and Appointment Time should be blank");
        } 
       }
     </script>
 
VF code for command button: 

<apex:pageBlock id="pageBlock2" title="SDR-BDR Qualification Criteria">
        <apex:pageMessages />
        <apex:pageBlockButtons location="bottom">
            <apex:commandButton id="btnUpdate" onclick="validateType();" action="{! IF(error==FALSE,{!Save},NULL)}" status="status" value="Update Opportunity"/>
            <apex:commandButton id="btnCance" action="{!Cancel}" value="Cancel"/>
        </apex:pageBlockButtons>

 
  • June 14, 2017
  • Like
  • 0
Hello,

Need help on javascript validation on a visualforce page. The VF page itself is using the standard controller for Opportunity. I'm new to vf page and js, so I'm unsure what I'm missing. Any feedback is appreciated. 

<script>
    function validateType(){
        var valType = document.getElementById'{!$Component.form.pageBlock2.initialFollowType.outputType.Type}').value;
if(valType.value=="Email")
            {
                alert("If Initial Follow Up Type = Phone or Email, Follow Up Date is Required, Follow Up Time of Day is Required, and Appointment Time should be blank");
                return false;
            }else
            {
              if(valType =="Phone"&& valDate ==NULL && valTimeofDay ==NULL && valTime !=NULL)
              {
                    alert("If Initial Follow Up Type = Phone or Email, Follow Up Date is Required, Follow Up Time of Day is Required, and Appointment Time should be blank");
                    return false;
              }
             }return true;        
                            
     </script>
  • June 08, 2017
  • Like
  • 0
Hello,  

I'm new at writing apex class and test class. I've written a class that's updating a SubMarket field in an account from a Custom Setting. I've created a test class to test if the SubMarket field value on the account matches the value from the SubMarket in the custom setting. I'm only getting 69% code coverage. I'm not sure what I'm missing/need to add to increase my code coverage. Any feedback would be greatly appreciated. 

Apex class: 
public class AccountSubMarketUpdate {
    public static void setSubMarket(List<Account> acctList){
  
        Set<String> billingCountries = new Set<String>(); 
     
        List<Account> finalAccount = new List<Account>();
        for( Account a : acctList){
            if(String.isBlank(a.SubMarket__c)){
               billingCountries.add(a.BillingCountry); 
               finalAccount.add(a);
            }
        }
           Map<String,CountryMarketMatchMap__c> marketName = CountryMarketMatchMap__c.getAll(); 
        Map<String,String> finalsubMarket = new Map<String,String>(); 
        for (CountryMarketMatchMap__c m : marketName.values()){
               finalsubMarket.put(m.Name,m.Sub_Market__c);
                  }
        for(Account a: finalAccount){
            a.SubMarket__c  = finalsubMarket.get(a.BillingCountry); 
           }
        }
}
   
TestClass: 
@isTest
public class AccountSubMarketUpdateTest {
    @testSetup static void setupTests(){
        List<TriggerController__c> tc = new List<TriggerController__c>{
            new TriggerController__c(Name='Account', Disabled__c=false)
        };
            insert tc; 
    }
    
    static testMethod void testSubMarketUpdate(){
        List<Account> newAcctList = new List<Account>();
        
        Account a1 = new Account();
        a1.name = 'AcctSubMarket';
        a1.BillingCountry = 'Albania';
        a1.SubMarket__c = 'ROE';
        
        Account a2 = new Account();
        a2.name = 'AcctNoMatchSubMarket'; 
        a2.BillingCOuntry = 'Albania';
        a2.SubMarket__c = 'ROE'; 
        
        Test.startTest();
        insert(a1); 
        insert(a2); 
        Test.stopTest();
        
   //Test1: Acct SubMarket matches CS SubMarket.   
        CountryMarketMatchMap__c request = new CountryMarketMatchMap__c();
        request.Sub_Market__c ='ROE';
        request.Name ='Albania'; 
   
        Account returnMarket = [SELECT Id,SubMarket__c,BillingCountry FROM Account WHERE Id =:a1.Id LIMIT 1];
        System.assertEquals(request.Name, returnMarket.BillingCountry);
        System.assertEquals(request.Sub_Market__c, returnMarket.SubMarket__c);
        
   //Test2: Acct SubMarket does not match CS SubMarket. 
           CountryMarketMatchMap__c request2 = new CountryMarketMatchMap__c();
        request2.Sub_Market__c = 'Africa';
        request2.Name = 'Albania'; 
        
        Account noMatchMarket = [SELECT Id,SubMarket__c,BillingCountry FROM Account WHERE Id =:a2.Id LIMIT 1];
        System.assertNotEquals(noMatchMarket.SubMarket__c, 'Africa');
    
    }
}
  • May 22, 2017
  • Like
  • 0
Hello,

Is it possible to store picklist value as a separate variables in visualflow? If so, please help! 

thank you! 
  • November 18, 2016
  • Like
  • 0
Hello, 

I am having problems with pulling the "Name" of the Account Team Members into the table in a flow. I was able to successfully pull the account team members' Id, Title, and TeamMemberRole. I tried to do the lookup for account team members object first, then do a for loop, then do a lookup to the user object, then pointing it back to the for loop, then pointing it to an assignment (see screenshot). This isn't working though. Any insight would be appreciated. 
User-added image
  • November 16, 2016
  • Like
  • 0
Hello, 

New to writing trigger so I'm unsure why I'm getting the Id is not specified error. Goal is if an existing user record's Channel OR LOB field  is updated then, it should look for existing User History record and update the Role_End_Date__c and create a new history record with for that same user with the Role_Start_Date__c as today. 
 
public class UserHistory_CreateUpdateFromUser  {

	public static void findUser(List<User> newUsers, Map<Id,User> oldUsers, Boolean isInsert){

		List<User> newUserList = new List<User>(); 
		List<User> lOBChannelList = new List<User>();
		List<User> isActiveList = new List<User>(); 
		List<User> uManagerLOBChannelList = new List<User>();
        List<User> uManagerList = new List<User>(); 
		Map<Id,List<User>> reasonForUpdatingUser = new Map<Id,List<User>>(); 
			
       	for(User u : newUsers){
            //New user && Channel != Non Sales  
            if(u.Channel__c != 'Non Sales'){
                if(isInsert){ 
       				newUserList.add(u); 
       				System.debug('newUserList: '+ newUserList); 
       			}
                //Existing user && Channel || LOB is changed 
       			else if(!isInsert && (u.Channel__c != oldUsers.get(u.Id).Channel__c || u.LOB_Focus__c != oldUsers.get(u.Id).LOB_Focus__c)) {
       				lOBChannelList.add(u); 
       				System.debug('lOBChannelList: '+ lOBChannelList); 
       			}
       			//Existing user && deactived 
       			else if(!isInsert && u.IsActive != oldUsers.get(u.Id).IsActive){
       				isActiveList.add(u); 
       				System.debug('isActiveList: '+ isActiveList);
                }
                //Existing user && Manager is changed && Channel || LOB is changed 
       			else if(!isInsert && u.ManagerId != oldUsers.get(u.Id).ManagerId &&
                        (u.Channel__c != oldUsers.get(u.Id).Channel__c || u.LOB_Focus__c != oldUsers.get(u.Id).LOB_Focus__c)){
       				uManagerLOBChannelList.add(u); 
       				System.debug('uManagerLOBChannelList: '+ uManagerLOBChannelList);
       			}
       			//Existing user && Manager is changed 
                else if(!isInsert && u.ManagerId != oldUsers.get(u.Id).ManagerId){
                    uManagerList.add(u); 
                    System.debug('uManagerList: '+ uManagerList);
                }
            }     
       	}

       	if(newUserList.size()>0){
       		newUser(newUserList);
       	}	

       	if(lOBChannelList.size()>0){
       		lOBChannelUpdate(lOBChannelList); 
       	}

       	if(isActiveList.size()>0){
       		userisActiveUpdate(isActiveList); 
       	}

       	if(uManagerList.size()>0){
       		managerUpdateOnly(uManagerList); 
       	}

       	if(uManagerLOBChannelList.size()>0){
       		managerLOBChannelUpdate(uManagerLOBChannelList); 
       	}
       
	}

	public static void lOBChannelUpdate(List<User> lOBChannelList){
		//Find existing User History record and update end date fields 
		//Create new user history record and update fields based on user changes 

		List<Id> userIds = new List<Id>(); 
		List<User_History__c> existingUHtoUpdate = new List<User_History__c>(); 
		List<User_History__c> newUHtoInsert = new List<User_History__c>(); 

		for(User u : lOBChannelList){
			userIds.add(u.Id); 
		}
		System.debug('userIds: '+ userIds);
		System.debug('lOBChannelList: '+ lOBChannelList);

		if(userIds.size()>0){
			List<User_History__c> eUH = [SELECT Id, User__C, Role_End_Date__c, Manager_End_Date__c FROM User_History__c
											WHERE User__c =:userIds]; 
            System.debug('eUH' + eUH); 

			for(User_History__c uH : eUH){

                User_History__c existingUH = new User_History__c(); 
                
                if(uH.Role_End_Date__c == NULL){
					existingUH.Role_End_Date__c = Date.today(); 
					existingUH.Id = uH.Id;
                }
                else if(uH.Manager_End_Date__c == NULL){
					existingUH.Manager_End_Date__c = Date.today(); 
					existingUH.Id = uH.Id;
                }
                else if(uH.Role_End_Date__c == NULL && uH.Manager_End_Date__c == NULL){
                    existingUH.Role_End_Date__c = Date.today(); 
                    existingUH.Manager_End_Date__c = Date.today(); 
                    existingUH.Id = uH.Id;
                }
				existingUHtoUpdate.add(existingUH); 
			}
			System.debug('existingUHtoUpdate: '+ existingUHtoUpdate);

			for(User u1 : lOBChannelList){
                
				User_History__c newUH = new User_History__c(
				User__c = u1.Id, 
				Channel__c = u1.Channel__c,  
				LOB_Focus__c = u1.LOB_Focus__c,  
				Role_Start_Date__c = Date.today(), 
				Manager_Start_Date__c = Date.today()
			); 
				newUHtoInsert.add(newUH); 
				
			}	
			System.debug('newUHtoInsert: '+ newUHtoInsert);
		}

		if(!existingUHtoUpdate.isempty()){
			Database.update(existingUHtoUpdate); 
		}
		System.debug('Databaseupdate existingUHtoUpdate: ' + existingUHtoUpdate); 

		if(!newUHtoInsert.isempty()){
			Database.insert(newUHtoInsert);
		}

	}
I've checked on the debug log that it is finding the Id of the existing User History record when I do the query and added it on the list 'eUH' and looped through that list. 

 
  • October 17, 2017
  • Like
  • 1
Just getting more practice with formulas but have run into an obstacle. Hopefully I'm overthinking it, but I'm writing a throw away formula:

IF( AnnualRevenue >= 1000000, NumberOfEmployees, " ???  ")

The goal is to throw an error message telling the user if the "AnnualRevenue" is greater than or equal to one million, then the "NumberOfEmployees" field is mandatory, else do nothing. What value do I need to enter in the "false" field? I've tried using "null" however there needs to be an actual value. Is using an "IF" statement the wrong route to take for this goal?

Any assistance is more than welcome. Thanks in adnvacned!!
I have a visual flow that is supposed to update some fields upon lead conversion but it isn't doing it. Everything looks correct to me, I feel like something is broken? Can anyone help me troubleshoot?

Hello Salesforce World!

I have a number of validation rules set up for leads.

This is for making sure details are there as the lead proceeds it's life from Lead to Opp.

However, I want to cancel most of my validation rules if in the discovery process the lead is unqualified or is to be closed.

Please Help!

Hello,

Need help on javascript validation on a visualforce page. The VF page itself is using the standard controller for Opportunity. I'm new to vf page and js, so I'm unsure what I'm missing. Any feedback is appreciated. 

<script>
    function validateType(){
        var valType = document.getElementById'{!$Component.form.pageBlock2.initialFollowType.outputType.Type}').value;
if(valType.value=="Email")
            {
                alert("If Initial Follow Up Type = Phone or Email, Follow Up Date is Required, Follow Up Time of Day is Required, and Appointment Time should be blank");
                return false;
            }else
            {
              if(valType =="Phone"&& valDate ==NULL && valTimeofDay ==NULL && valTime !=NULL)
              {
                    alert("If Initial Follow Up Type = Phone or Email, Follow Up Date is Required, Follow Up Time of Day is Required, and Appointment Time should be blank");
                    return false;
              }
             }return true;        
                            
     </script>
  • June 08, 2017
  • Like
  • 0