-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
5Questions
-
5Replies
Can't assign people record from log event in LFO.
Hi Gurus,
I am using LFO (but not Lighting Sync) and found a few issues during my test.
1. Outlook Calendar event does not find a related record from the custom object.
2. During Log Event, I can search and relate even to custom record but people records are gray out ( Can't assign an event to listed people). Calendar - OWD (Hide Details and Add Events).
Any help here?
I am using LFO (but not Lighting Sync) and found a few issues during my test.
1. Outlook Calendar event does not find a related record from the custom object.
2. During Log Event, I can search and relate even to custom record but people records are gray out ( Can't assign an event to listed people). Calendar - OWD (Hide Details and Add Events).
Any help here?
-
- Sunny Solanki 11
- February 21, 2019
- Like
- 0
Acitivty Due Date not populating per the code....need export advise.
Hi Gurus,
I am not too technical so have to write this post to understand why the existing code not working to populate activity due date on contact record. ObjectFieldMapping__c is custom setting object with few fields but no data set is entered underneath. I am supspecting issue is there as we don't have any date there, but since I am not expert I am posting my code here so you can assist me. There is a trigger on task and helper class which call this custom setting. Thank you in advance.
I am not too technical so have to write this post to understand why the existing code not working to populate activity due date on contact record. ObjectFieldMapping__c is custom setting object with few fields but no data set is entered underneath. I am supspecting issue is there as we don't have any date there, but since I am not expert I am posting my code here so you can assist me. There is a trigger on task and helper class which call this custom setting. Thank you in advance.
Trigger:
-------------
trigger TaskTrigger on Task (after insert,after update) {
list<ObjectFieldMapping__c> lstObjectFieldMappingInfo=ActivityHelper.getObjectFieldMappingInfo('LastRelationshipType-Condition','Task');
list<ObjectFieldMapping__c> lstObjectFieldMappingInfoFieldUpdate=ActivityHelper.getObjectFieldMappingInfo('LastRelationshipType-FieldUpdate','Task');
map<Id,Sobject> mapSobjectToUpdate=new map<Id,Sobject>();
List<ObjectFieldMapping__c> lstContactFieldUpdateInfo=new List<ObjectFieldMapping__c>();
List<ObjectFieldMapping__c> lstLeadFieldUpdateInfo=new List<ObjectFieldMapping__c>();
for(ObjectFieldMapping__c objObjectFieldMapping : lstObjectFieldMappingInfoFieldUpdate){
if(objObjectFieldMapping.Target_Object_Name__c != null ){
set<string> setObjectName=new set<string>();
setObjectName.addall(objObjectFieldMapping.Target_Object_Name__c.split(','));
if(setObjectName.contains('Contact')){
lstContactFieldUpdateInfo.add(objObjectFieldMapping);
}
else if(setObjectName.contains('Lead')){
lstLeadFieldUpdateInfo.add(objObjectFieldMapping);
}
}
}
set<Id> setIds=new set<Id>();
for(Task objTask : trigger.new){
if(objTask.WhoId != null){
setIds.add(objTask.WhoId);
}
}
map<Id,Contact> mapContact=new map<Id,Contact>([select id,Last_Relationship_Call__c from contact where id in :setIds]);
map<Id,Lead> mapLead=new map<Id,Lead>([select id,Last_Relationship_Call__c from Lead where id in :setIds]);
system.debug('****lstObjectFieldMappingInfo***'+lstObjectFieldMappingInfo);
for(Task objTask : trigger.new){
if(objTask.WhoId != null){
integer counter=0;
boolean isSubjectEmail=false;
for(ObjectFieldMapping__c objMapping : lstObjectFieldMappingInfo){
set<string> sValues=new set<string>();
sValues.addall(objMapping.Field_Value__c.split(','));
system.debug('*****'+sValues + '****'+objTask.get(objMapping.Field_API_Name__c));
if(sValues.contains((string)objTask.get(objMapping.Field_API_Name__c))){
counter++;
}
}
if(objTask.subject != null && objTask.subject.startsWithIgnoreCase('email')){
counter++;
isSubjectEmail=true;
}
if(counter > 0){
Sobject objSobject=objTask.WhoId.getSObjectType().newSObject();
objSobject.put('Id',objTask.WhoId);
if(mapContact.containsKey(objTask.WhoId)){
if(objTask.Call_Note_Type__c == 'Note'){
objSobject.put('Last_Note_Date__c',system.today());
}
else{
if(mapContact.get(objTask.WhoId).Last_Relationship_Call__c== null || (mapContact.get(objTask.WhoId).Last_Relationship_Call__c != null &&
mapContact.get(objTask.WhoId).Last_Relationship_Call__c < system.today())){
objSobject.put('Last_Relationship_Call__c',system.today());
}
}
for(ObjectFieldMapping__c objObjectFieldMapping : lstContactFieldUpdateInfo){
objSobject.put(objObjectFieldMapping.Target_Object_Field_Name__c,objObjectFieldMapping.Target_Object_Field_Value__c);
}
if(isSubjectEmail)
objSobject.put('Last_Email_Date__c',system.today());
}
else if(mapLead.containsKey(objTask.WhoId)){
if(objTask.Call_Note_Type__c == 'Note'){
objSobject.put('Last_Note_Date__c',system.today());
}
else{
if( mapLead.get(objTask.WhoId).Last_Relationship_Call__c == null || (mapLead.get(objTask.WhoId).Last_Relationship_Call__c != null &&
mapLead.get(objTask.WhoId).Last_Relationship_Call__c < system.today())){
objSobject.put('Last_Relationship_Call__c',system.today());
}
}
for(ObjectFieldMapping__c objObjectFieldMapping : lstLeadFieldUpdateInfo){
objSobject.put(objObjectFieldMapping.Target_Object_Field_Name__c,objObjectFieldMapping.Target_Object_Field_Value__c);
}
}
if(!mapSobjectToUpdate.containsKey(objTask.WhoId))
mapSobjectToUpdate.put(objTask.WhoId,objSobject);
}
}
}
update mapSobjectToUpdate.values();
Helper Class:
------------------
public class ActivityHelper {
public static list<ObjectFieldMapping__c> getObjectFieldMappingInfo(string sFunctionalityType,string sObjectName){
list<ObjectFieldMapping__c> lstObjectFieldMapping=new list<ObjectFieldMapping__c>();
list<ObjectFieldMapping__c> lstObjectFieldMappingInfo= ObjectFieldMapping__c.getAll().values();
if(lstObjectFieldMappingInfo != null && !lstObjectFieldMappingInfo.isEmpty()){
for(ObjectFieldMapping__c objFieldMapping : lstObjectFieldMappingInfo){
if(objFieldMapping.Functionality_Type__c != null && objFieldMapping.Functionality_Type__c.equals(sFunctionalityType) && objFieldMapping.Object_API_Name__c.equals(sObjectName)){
lstObjectFieldMapping.add(objFieldMapping);
}
}
}
return lstObjectFieldMapping;
}
}
-
- Sunny Solanki 11
- November 01, 2018
- Like
- 0
Delete Trigger code not working
Hi Guys,
I have following Trigger code which is working fine during add but during an update or (especially) deletes it is not updating "invveh.Number_of_Current_Investors__c" value. I think it is because "if(numofcurrentinvestorsMap.containsKey(id))" statement.
Also attaching test class, hope this will help. After delete record in test class assertion failing to validate "TestInvestmentVehicle1[0].Number_of_Current_Investors__c".
I need your expert advice to fix this code.
I have following Trigger code which is working fine during add but during an update or (especially) deletes it is not updating "invveh.Number_of_Current_Investors__c" value. I think it is because "if(numofcurrentinvestorsMap.containsKey(id))" statement.
Also attaching test class, hope this will help. After delete record in test class assertion failing to validate "TestInvestmentVehicle1[0].Number_of_Current_Investors__c".
I need your expert advice to fix this code.
trigger InvestorPositionTrigger on Investor_Position__c (after insert, after update, after delete) {
Set<Id> numofhistinvestors = new Set<Id>();
Set<Id> numofcurrentinvestors = new Set<Id>();
Set<Id> InvestmentVehicleIds = new Set<Id>();
List<Investment_Vehicle__c> lstUpdateInvVehicle = new List<Investment_Vehicle__c>();
if(trigger.isafter)
{
//if(RecursiveHandler.flag)
//{
// RecursiveHandler.flag = false;
if(trigger.isinsert || trigger.isupdate)
{
for(Investor_Position__c inv : Trigger.New)
{
InvestmentVehicleIds.add(inv.Investment_Vehicle__c);
}
}
if(trigger.isdelete)
{
for(Investor_Position__c inv : Trigger.old)
{
InvestmentVehicleIds.add(inv.Investment_Vehicle__c);
}
}
/*************************************************************************************
* Begaining of SOQL 101 issue fix code
************************************************************************************/
Map<String,Integer> numofcurrentinvestorsMap = new Map<String,Integer>();
Map<String,Integer> numofhistinvestorsMap = new Map<String,Integer>();
for( Investor_Position__c obj : [Select Id,Investor_Position_Account__c,Is_Active__c, Current_Commitments_Functional__c, Source_of_Capital__c,
Investment_Vehicle__r.Id, Investment_Vehicle__r.Number_of_Current_Investors__c, Investment_Vehicle__r.Number_of_Historical_Investors__c
from Investor_Position__c where Investment_Vehicle__r.Id IN:InvestmentVehicleIds])
{
if(obj.Is_Active__c == TRUE && obj.Source_of_Capital__c != null)
{
if(obj.Current_Commitments_Functional__c > 0 && (obj.Source_of_Capital__c.contains('Limited Partners') || obj.Source_of_Capital__c.contains('Operating Partner')))
{
if(numofcurrentinvestorsMap!=null && numofcurrentinvestorsMap.containsKey(obj.Investment_Vehicle__r.Id)){
numofcurrentinvestorsMap.put(obj.Investment_Vehicle__r.Id,numofcurrentinvestorsMap.get(obj.Investment_Vehicle__r.Id)+1);
}else{
numofcurrentinvestorsMap.put(obj.Investment_Vehicle__r.Id,1);
}
//numofcurrentinvestors.add(obj.Investor_Position_Account__c);
}
if(obj.Source_of_Capital__c.contains('Limited Partners') || obj.Source_of_Capital__c.contains('Operating Partner'))
{
if(numofhistinvestorsMap!=null && numofhistinvestorsMap.containsKey(obj.Investment_Vehicle__r.Id)){
numofhistinvestorsMap.put(obj.Investment_Vehicle__r.Id,numofhistinvestorsMap.get(obj.Investment_Vehicle__r.Id)+1);
}else{
numofhistinvestorsMap.put(obj.Investment_Vehicle__r.Id,1);
}
//numofhistinvestors.add(obj.Investor_Position_Account__c);
}
}
}
System.debug('Map numofcurrentinvestorsMap: ' + numofcurrentinvestorsMap.size());
System.debug('Map numofhistinvestorsMap: ' + numofhistinvestorsMap.size());
System.debug('Map numofcurrentinvestorsMap: ' + numofcurrentinvestorsMap);
System.debug('Map numofhistinvestorsMap: ' + numofhistinvestorsMap);
for(Id id : InvestmentVehicleIds)
{
Investment_Vehicle__c invveh = new Investment_Vehicle__c();
invveh.Id = id;
if(numofhistinvestorsMap.containsKey(id)){
invveh.Number_of_Historical_Investors__c = numofhistinvestorsMap.get(id);
System.debug('invveh.Number_of_Historical_Investors__c: ' + invveh.Number_of_Historical_Investors__c);
}
if(numofcurrentinvestorsMap.containsKey(id)){
invveh.Number_of_Current_Investors__c = numofcurrentinvestorsMap.get(id);
System.debug('invveh.Number_of_Current_Investors__c: ' + invveh.Number_of_Current_Investors__c);
}
lstUpdateInvVehicle.add(invveh);
System.debug('invveh.Number_of_Historical_Investors__c: ' + invveh);
//numofcurrentinvestors.clear();
//numofhistinvestors.clear();
}
System.debug('lstUpdateInvVehicle : ' + lstUpdateInvVehicle.size());
/*************************************************************************************
* SS: 7/18/18 - End of SOQL 101 issue fix code
************************************************************************************/
try
{
if(lstUpdateInvVehicle.size() > 0)
{
update lstUpdateInvVehicle;
}
}
catch(exception ex)
{
for (Investor_Position__c obj : trigger.new)
{
obj.addError(ex.getmessage());
}
}
//}
}
if(Trigger.isInsert){
ConfigurableRollup.rollup(trigger.new);
}
if(Trigger.isUpdate){
system.debug('when is update------');
ConfigurableRollup.rollup(trigger.new, Trigger.OldMap);
}
if(Trigger.isDelete){
ConfigurableRollup.rollup(trigger.old);
}
}
Test Class:
@isTest(SeeAllData=false)
private class Test_InvestorPositionTrigger {
static testMethod void myUnitTest() {
Account account = new Account(Name='Test' );
insert account;
Account account1 = new Account(Name='Test1' );
insert account1;
Investment_Vehicle__c invvehicle = new Investment_Vehicle__c(Name='TestInvestmentVehicle');
insert invvehicle;
//SS: 7/18/18 added following line of code for code coverage
Opportunity opt = new Opportunity(Name = 'NewTestOpportunity', StageName ='2 - Initiated General Contact', CloseDate = system.today() , Investment_Vehicle__c = invvehicle.id, AccountId = account.id, Consultant__c = account.id );
insert opt;
//Opportunity opt1 = new Opportunity(Name = 'NewTestOpportunity1', StageName ='2 - Initiated General Contact', CloseDate = system.today() , Investment_Vehicle__c = invvehicle.id, AccountId = account.id, Consultant__c = account.id );
//insert opt1;
Investor_Position__c invposition = new Investor_Position__c(As_of__c= System.Today() - 89 , Current_Commitments_Functional__c = 100000, Investor_Position_Account__c = account.Id, Investment_Vehicle__c = invvehicle.Id, Name='TestInvestorPosition', Source_of_Capital__c = 'Operating Partner', Is_Active__c=true, Opportunity_Name__c = opt.id);
insert invposition;
Investor_Position__c invposition1 = new Investor_Position__c(As_of__c= System.Today() -89 , Investor_Position_Account__c = account1.Id, Investment_Vehicle__c = invvehicle.Id, Name='TestInvestorPosition', Source_of_Capital__c = 'Operating Partner', Is_Active__c=true, Opportunity_Name__c = opt.id);
insert invposition1;
//SS: 7/18/18 end of the change.
test.startTest();
//SS: 7/18/18 updated following line of code : From: As_of_Last_quater_text__c TO: As_of_Is_last_quater__c
List<Investor_Position__c> InvPositionlst = [Select Id,As_of_Is_last_quater__c,As_of__c from Investor_Position__c where Investment_Vehicle__c =: invvehicle.Id];
for(Investor_Position__c inv : InvPositionlst)
{
System.debug( 'test2323' + inv.As_of_Is_last_quater__c);
System.debug('test2323' + inv.As_of__c);
}
system.debug('Test Investment Positions: ' + InvPositionlst.size());
// SS: 7/18/18 end of change.
System.assertequals(InvPositionlst.size(),2);
List<Investment_Vehicle__c> TestInvestmentVehicle = [Select Number_of_Historical_Investors__c, Number_of_Current_Investors__c from Investment_Vehicle__c where Id =: invvehicle.Id];
System.assertequals(TestInvestmentVehicle.size(),1);
//
System.debug('....Historical Investor -1 .......'+TestInvestmentVehicle[0].Number_of_Historical_Investors__c);
System.debug('....Current Investor -1 .......'+TestInvestmentVehicle[0].Number_of_Current_Investors__c);
//
System.assertequals(TestInvestmentVehicle[0].Number_of_Historical_Investors__c,2);
System.assertequals(TestInvestmentVehicle[0].Number_of_Current_Investors__c,1);
delete invposition;
List<Investment_Vehicle__c> TestInvestmentVehicle1 = [Select Number_of_Historical_Investors__c, Number_of_Current_Investors__c from Investment_Vehicle__c where Id =: invvehicle.Id];
System.assertequals(TestInvestmentVehicle1.size(),1);
System.debug('....Historical Investor -2 .......'+TestInvestmentVehicle1[0].Number_of_Historical_Investors__c);
System.debug('....Current Investor -2 .......'+TestInvestmentVehicle1[0].Number_of_Current_Investors__c);
System.assertequals(TestInvestmentVehicle1[0].Number_of_Historical_Investors__c,1);
System.assertequals(TestInvestmentVehicle1[0].Number_of_Current_Investors__c,0);
test.stopTest();
}
}
-
- Sunny Solanki 11
- July 24, 2018
- Like
- 0
SOQL 101 issue due to query in for loop. Need help
I have the following trigger which is poorly written and causing during data load and record update for certain records. I am trying to fix the query issue at list for now. But I am not expert like you guys so need help.
Following Code trying to update but getting- Unexpected token issue.
Original Code:
Following Code trying to update but getting- Unexpected token issue.
List <Investor_Position__c> listIvPost = [Select Id,Investor_Position_Account__c,Is_Active__c, Current_Commitments_Functional__c, Source_of_Capital__c,
Investment_Vehicle__r.Id, Investment_Vehicle__r.Number_of_Current_Investors__c, Investment_Vehicle__r.Number_of_Historical_Investors__c
from Investor_Position__c where Investment_Vehicle__r.Id IN InvestmentVehicleIds];
for(Id id : InvestmentVehicleIds)
{
for( Investor_Position__c obj :listIvPost )
{
if(obj.Is_Active__c == TRUE && obj.Source_of_Capital__c != null)
{
Original Code:
trigger InvestorPositionTrigger on Investor_Position__c (after insert, after update, after delete) {
Set<Id> numofhistinvestors = new Set<Id>();
Set<Id> numofcurrentinvestors = new Set<Id>();
Set<Id> InvestmentVehicleIds = new Set<Id>();
List<Investment_Vehicle__c> lstUpdateInvVehicle = new List<Investment_Vehicle__c>();
if(trigger.isafter)
{
if(trigger.isinsert || trigger.isupdate)
{
for(Investor_Position__c inv : Trigger.New)
{
InvestmentVehicleIds.add(inv.Investment_Vehicle__c);
}
}
if(trigger.isdelete)
{
for(Investor_Position__c inv : Trigger.old)
{
InvestmentVehicleIds.add(inv.Investment_Vehicle__c);
}
}
for(Id id : InvestmentVehicleIds)
{
for( Investor_Position__c obj : [Select Id,Investor_Position_Account__c,Is_Active__c, Current_Commitments_Functional__c, Source_of_Capital__c,
Investment_Vehicle__r.Id, Investment_Vehicle__r.Number_of_Current_Investors__c, Investment_Vehicle__r.Number_of_Historical_Investors__c
from Investor_Position__c where Investment_Vehicle__r.Id =:id])
{
if(obj.Is_Active__c == TRUE && obj.Source_of_Capital__c != null)
{
if(obj.Current_Commitments_Functional__c > 0 && (obj.Source_of_Capital__c.contains('Limited Partners') || obj.Source_of_Capital__c.contains('Operating Partner')))
{
numofcurrentinvestors.add(obj.Investor_Position_Account__c);
}
if(obj.Source_of_Capital__c.contains('Limited Partners') || obj.Source_of_Capital__c.contains('Operating Partner'))
{
numofhistinvestors.add(obj.Investor_Position_Account__c);
}
}
}
Investment_Vehicle__c invveh = new Investment_Vehicle__c();
invveh.Id = id;
invveh.Number_of_Historical_Investors__c = numofhistinvestors.size();
invveh.Number_of_Current_Investors__c = numofcurrentinvestors.size();
lstUpdateInvVehicle.add(invveh);
numofcurrentinvestors.clear();
numofhistinvestors.clear();
}
try
{
if(lstUpdateInvVehicle.size() > 0)
{
update lstUpdateInvVehicle;
}
}
catch(exception ex)
{
for (Investor_Position__c obj : trigger.new)
{
obj.addError(ex.getmessage());
}
}
}
if(Trigger.isInsert){
ConfigurableRollup.rollup(trigger.new);
}
if(Trigger.isUpdate){
system.debug('when is update------');
ConfigurableRollup.rollup(trigger.new, Trigger.OldMap);
}
if(Trigger.isDelete){
ConfigurableRollup.rollup(trigger.old);
}
}
-
- Sunny Solanki 11
- July 17, 2018
- Like
- 0
Batch fail with caused by: System.QueryException: Variable does not exist: Label.CustomObject_Record_Type
Hi Gurus,
I have a batch class where I am using the custom label to limit result by record type and doing a blank update on the result. Batch class has been scheduled and failing with: Source organization: ****************8(null) Failed to process batch for class 'BatchBlankUpdateCompliance' for job id '7074D00000LzJIL'. Please, can anyone assist me the correct this error?
caused by: System.QueryException: Variable does not exist: Label.PSG_Compliance_Record_Type
Class.BatchBlankUpdateCompliance.start: line 7, column 1
global class BatchBlankUpdateCompliance implements
Database.Batchable<sObject>, Database.Stateful {
// instance member to retain state across transactions
global Integer recordsProcessed = 0;
global Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator(
'SELECT ID FROM Compliance__c ' +
'Where RecordTypeId =: Label.CustomObject_Record_Type'
);
}
global void execute(Database.BatchableContext bc, List<Compliance__c> scope){
// process each batch of records
List<Compliance__c> compList = New List<Compliance__c>();
for (Compliance__c comp : scope) {
compList.add(comp);
recordsProcessed = recordsProcessed + 1;
}
update compList;
}
global void finish(Database.BatchableContext bc){
System.debug(recordsProcessed + ' records processed. Shazam!');
I have a batch class where I am using the custom label to limit result by record type and doing a blank update on the result. Batch class has been scheduled and failing with: Source organization: ****************8(null) Failed to process batch for class 'BatchBlankUpdateCompliance' for job id '7074D00000LzJIL'. Please, can anyone assist me the correct this error?
caused by: System.QueryException: Variable does not exist: Label.PSG_Compliance_Record_Type
Class.BatchBlankUpdateCompliance.start: line 7, column 1
global class BatchBlankUpdateCompliance implements
Database.Batchable<sObject>, Database.Stateful {
// instance member to retain state across transactions
global Integer recordsProcessed = 0;
global Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator(
'SELECT ID FROM Compliance__c ' +
'Where RecordTypeId =: Label.CustomObject_Record_Type'
);
}
global void execute(Database.BatchableContext bc, List<Compliance__c> scope){
// process each batch of records
List<Compliance__c> compList = New List<Compliance__c>();
for (Compliance__c comp : scope) {
compList.add(comp);
recordsProcessed = recordsProcessed + 1;
}
update compList;
}
global void finish(Database.BatchableContext bc){
System.debug(recordsProcessed + ' records processed. Shazam!');
-
- Sunny Solanki 11
- July 16, 2018
- Like
- 0
Delete Trigger code not working
Hi Guys,
I have following Trigger code which is working fine during add but during an update or (especially) deletes it is not updating "invveh.Number_of_Current_Investors__c" value. I think it is because "if(numofcurrentinvestorsMap.containsKey(id))" statement.
Also attaching test class, hope this will help. After delete record in test class assertion failing to validate "TestInvestmentVehicle1[0].Number_of_Current_Investors__c".
I need your expert advice to fix this code.
I have following Trigger code which is working fine during add but during an update or (especially) deletes it is not updating "invveh.Number_of_Current_Investors__c" value. I think it is because "if(numofcurrentinvestorsMap.containsKey(id))" statement.
Also attaching test class, hope this will help. After delete record in test class assertion failing to validate "TestInvestmentVehicle1[0].Number_of_Current_Investors__c".
I need your expert advice to fix this code.
trigger InvestorPositionTrigger on Investor_Position__c (after insert, after update, after delete) {
Set<Id> numofhistinvestors = new Set<Id>();
Set<Id> numofcurrentinvestors = new Set<Id>();
Set<Id> InvestmentVehicleIds = new Set<Id>();
List<Investment_Vehicle__c> lstUpdateInvVehicle = new List<Investment_Vehicle__c>();
if(trigger.isafter)
{
//if(RecursiveHandler.flag)
//{
// RecursiveHandler.flag = false;
if(trigger.isinsert || trigger.isupdate)
{
for(Investor_Position__c inv : Trigger.New)
{
InvestmentVehicleIds.add(inv.Investment_Vehicle__c);
}
}
if(trigger.isdelete)
{
for(Investor_Position__c inv : Trigger.old)
{
InvestmentVehicleIds.add(inv.Investment_Vehicle__c);
}
}
/*************************************************************************************
* Begaining of SOQL 101 issue fix code
************************************************************************************/
Map<String,Integer> numofcurrentinvestorsMap = new Map<String,Integer>();
Map<String,Integer> numofhistinvestorsMap = new Map<String,Integer>();
for( Investor_Position__c obj : [Select Id,Investor_Position_Account__c,Is_Active__c, Current_Commitments_Functional__c, Source_of_Capital__c,
Investment_Vehicle__r.Id, Investment_Vehicle__r.Number_of_Current_Investors__c, Investment_Vehicle__r.Number_of_Historical_Investors__c
from Investor_Position__c where Investment_Vehicle__r.Id IN:InvestmentVehicleIds])
{
if(obj.Is_Active__c == TRUE && obj.Source_of_Capital__c != null)
{
if(obj.Current_Commitments_Functional__c > 0 && (obj.Source_of_Capital__c.contains('Limited Partners') || obj.Source_of_Capital__c.contains('Operating Partner')))
{
if(numofcurrentinvestorsMap!=null && numofcurrentinvestorsMap.containsKey(obj.Investment_Vehicle__r.Id)){
numofcurrentinvestorsMap.put(obj.Investment_Vehicle__r.Id,numofcurrentinvestorsMap.get(obj.Investment_Vehicle__r.Id)+1);
}else{
numofcurrentinvestorsMap.put(obj.Investment_Vehicle__r.Id,1);
}
//numofcurrentinvestors.add(obj.Investor_Position_Account__c);
}
if(obj.Source_of_Capital__c.contains('Limited Partners') || obj.Source_of_Capital__c.contains('Operating Partner'))
{
if(numofhistinvestorsMap!=null && numofhistinvestorsMap.containsKey(obj.Investment_Vehicle__r.Id)){
numofhistinvestorsMap.put(obj.Investment_Vehicle__r.Id,numofhistinvestorsMap.get(obj.Investment_Vehicle__r.Id)+1);
}else{
numofhistinvestorsMap.put(obj.Investment_Vehicle__r.Id,1);
}
//numofhistinvestors.add(obj.Investor_Position_Account__c);
}
}
}
System.debug('Map numofcurrentinvestorsMap: ' + numofcurrentinvestorsMap.size());
System.debug('Map numofhistinvestorsMap: ' + numofhistinvestorsMap.size());
System.debug('Map numofcurrentinvestorsMap: ' + numofcurrentinvestorsMap);
System.debug('Map numofhistinvestorsMap: ' + numofhistinvestorsMap);
for(Id id : InvestmentVehicleIds)
{
Investment_Vehicle__c invveh = new Investment_Vehicle__c();
invveh.Id = id;
if(numofhistinvestorsMap.containsKey(id)){
invveh.Number_of_Historical_Investors__c = numofhistinvestorsMap.get(id);
System.debug('invveh.Number_of_Historical_Investors__c: ' + invveh.Number_of_Historical_Investors__c);
}
if(numofcurrentinvestorsMap.containsKey(id)){
invveh.Number_of_Current_Investors__c = numofcurrentinvestorsMap.get(id);
System.debug('invveh.Number_of_Current_Investors__c: ' + invveh.Number_of_Current_Investors__c);
}
lstUpdateInvVehicle.add(invveh);
System.debug('invveh.Number_of_Historical_Investors__c: ' + invveh);
//numofcurrentinvestors.clear();
//numofhistinvestors.clear();
}
System.debug('lstUpdateInvVehicle : ' + lstUpdateInvVehicle.size());
/*************************************************************************************
* SS: 7/18/18 - End of SOQL 101 issue fix code
************************************************************************************/
try
{
if(lstUpdateInvVehicle.size() > 0)
{
update lstUpdateInvVehicle;
}
}
catch(exception ex)
{
for (Investor_Position__c obj : trigger.new)
{
obj.addError(ex.getmessage());
}
}
//}
}
if(Trigger.isInsert){
ConfigurableRollup.rollup(trigger.new);
}
if(Trigger.isUpdate){
system.debug('when is update------');
ConfigurableRollup.rollup(trigger.new, Trigger.OldMap);
}
if(Trigger.isDelete){
ConfigurableRollup.rollup(trigger.old);
}
}
Test Class:
@isTest(SeeAllData=false)
private class Test_InvestorPositionTrigger {
static testMethod void myUnitTest() {
Account account = new Account(Name='Test' );
insert account;
Account account1 = new Account(Name='Test1' );
insert account1;
Investment_Vehicle__c invvehicle = new Investment_Vehicle__c(Name='TestInvestmentVehicle');
insert invvehicle;
//SS: 7/18/18 added following line of code for code coverage
Opportunity opt = new Opportunity(Name = 'NewTestOpportunity', StageName ='2 - Initiated General Contact', CloseDate = system.today() , Investment_Vehicle__c = invvehicle.id, AccountId = account.id, Consultant__c = account.id );
insert opt;
//Opportunity opt1 = new Opportunity(Name = 'NewTestOpportunity1', StageName ='2 - Initiated General Contact', CloseDate = system.today() , Investment_Vehicle__c = invvehicle.id, AccountId = account.id, Consultant__c = account.id );
//insert opt1;
Investor_Position__c invposition = new Investor_Position__c(As_of__c= System.Today() - 89 , Current_Commitments_Functional__c = 100000, Investor_Position_Account__c = account.Id, Investment_Vehicle__c = invvehicle.Id, Name='TestInvestorPosition', Source_of_Capital__c = 'Operating Partner', Is_Active__c=true, Opportunity_Name__c = opt.id);
insert invposition;
Investor_Position__c invposition1 = new Investor_Position__c(As_of__c= System.Today() -89 , Investor_Position_Account__c = account1.Id, Investment_Vehicle__c = invvehicle.Id, Name='TestInvestorPosition', Source_of_Capital__c = 'Operating Partner', Is_Active__c=true, Opportunity_Name__c = opt.id);
insert invposition1;
//SS: 7/18/18 end of the change.
test.startTest();
//SS: 7/18/18 updated following line of code : From: As_of_Last_quater_text__c TO: As_of_Is_last_quater__c
List<Investor_Position__c> InvPositionlst = [Select Id,As_of_Is_last_quater__c,As_of__c from Investor_Position__c where Investment_Vehicle__c =: invvehicle.Id];
for(Investor_Position__c inv : InvPositionlst)
{
System.debug( 'test2323' + inv.As_of_Is_last_quater__c);
System.debug('test2323' + inv.As_of__c);
}
system.debug('Test Investment Positions: ' + InvPositionlst.size());
// SS: 7/18/18 end of change.
System.assertequals(InvPositionlst.size(),2);
List<Investment_Vehicle__c> TestInvestmentVehicle = [Select Number_of_Historical_Investors__c, Number_of_Current_Investors__c from Investment_Vehicle__c where Id =: invvehicle.Id];
System.assertequals(TestInvestmentVehicle.size(),1);
//
System.debug('....Historical Investor -1 .......'+TestInvestmentVehicle[0].Number_of_Historical_Investors__c);
System.debug('....Current Investor -1 .......'+TestInvestmentVehicle[0].Number_of_Current_Investors__c);
//
System.assertequals(TestInvestmentVehicle[0].Number_of_Historical_Investors__c,2);
System.assertequals(TestInvestmentVehicle[0].Number_of_Current_Investors__c,1);
delete invposition;
List<Investment_Vehicle__c> TestInvestmentVehicle1 = [Select Number_of_Historical_Investors__c, Number_of_Current_Investors__c from Investment_Vehicle__c where Id =: invvehicle.Id];
System.assertequals(TestInvestmentVehicle1.size(),1);
System.debug('....Historical Investor -2 .......'+TestInvestmentVehicle1[0].Number_of_Historical_Investors__c);
System.debug('....Current Investor -2 .......'+TestInvestmentVehicle1[0].Number_of_Current_Investors__c);
System.assertequals(TestInvestmentVehicle1[0].Number_of_Historical_Investors__c,1);
System.assertequals(TestInvestmentVehicle1[0].Number_of_Current_Investors__c,0);
test.stopTest();
}
}

- Sunny Solanki 11
- July 24, 2018
- Like
- 0
SOQL 101 issue due to query in for loop. Need help
I have the following trigger which is poorly written and causing during data load and record update for certain records. I am trying to fix the query issue at list for now. But I am not expert like you guys so need help.
Following Code trying to update but getting- Unexpected token issue.
Original Code:
Following Code trying to update but getting- Unexpected token issue.
List <Investor_Position__c> listIvPost = [Select Id,Investor_Position_Account__c,Is_Active__c, Current_Commitments_Functional__c, Source_of_Capital__c,
Investment_Vehicle__r.Id, Investment_Vehicle__r.Number_of_Current_Investors__c, Investment_Vehicle__r.Number_of_Historical_Investors__c
from Investor_Position__c where Investment_Vehicle__r.Id IN InvestmentVehicleIds];
for(Id id : InvestmentVehicleIds)
{
for( Investor_Position__c obj :listIvPost )
{
if(obj.Is_Active__c == TRUE && obj.Source_of_Capital__c != null)
{
Original Code:
trigger InvestorPositionTrigger on Investor_Position__c (after insert, after update, after delete) {
Set<Id> numofhistinvestors = new Set<Id>();
Set<Id> numofcurrentinvestors = new Set<Id>();
Set<Id> InvestmentVehicleIds = new Set<Id>();
List<Investment_Vehicle__c> lstUpdateInvVehicle = new List<Investment_Vehicle__c>();
if(trigger.isafter)
{
if(trigger.isinsert || trigger.isupdate)
{
for(Investor_Position__c inv : Trigger.New)
{
InvestmentVehicleIds.add(inv.Investment_Vehicle__c);
}
}
if(trigger.isdelete)
{
for(Investor_Position__c inv : Trigger.old)
{
InvestmentVehicleIds.add(inv.Investment_Vehicle__c);
}
}
for(Id id : InvestmentVehicleIds)
{
for( Investor_Position__c obj : [Select Id,Investor_Position_Account__c,Is_Active__c, Current_Commitments_Functional__c, Source_of_Capital__c,
Investment_Vehicle__r.Id, Investment_Vehicle__r.Number_of_Current_Investors__c, Investment_Vehicle__r.Number_of_Historical_Investors__c
from Investor_Position__c where Investment_Vehicle__r.Id =:id])
{
if(obj.Is_Active__c == TRUE && obj.Source_of_Capital__c != null)
{
if(obj.Current_Commitments_Functional__c > 0 && (obj.Source_of_Capital__c.contains('Limited Partners') || obj.Source_of_Capital__c.contains('Operating Partner')))
{
numofcurrentinvestors.add(obj.Investor_Position_Account__c);
}
if(obj.Source_of_Capital__c.contains('Limited Partners') || obj.Source_of_Capital__c.contains('Operating Partner'))
{
numofhistinvestors.add(obj.Investor_Position_Account__c);
}
}
}
Investment_Vehicle__c invveh = new Investment_Vehicle__c();
invveh.Id = id;
invveh.Number_of_Historical_Investors__c = numofhistinvestors.size();
invveh.Number_of_Current_Investors__c = numofcurrentinvestors.size();
lstUpdateInvVehicle.add(invveh);
numofcurrentinvestors.clear();
numofhistinvestors.clear();
}
try
{
if(lstUpdateInvVehicle.size() > 0)
{
update lstUpdateInvVehicle;
}
}
catch(exception ex)
{
for (Investor_Position__c obj : trigger.new)
{
obj.addError(ex.getmessage());
}
}
}
if(Trigger.isInsert){
ConfigurableRollup.rollup(trigger.new);
}
if(Trigger.isUpdate){
system.debug('when is update------');
ConfigurableRollup.rollup(trigger.new, Trigger.OldMap);
}
if(Trigger.isDelete){
ConfigurableRollup.rollup(trigger.old);
}
}

- Sunny Solanki 11
- July 17, 2018
- Like
- 0
Batch fail with caused by: System.QueryException: Variable does not exist: Label.CustomObject_Record_Type
Hi Gurus,
I have a batch class where I am using the custom label to limit result by record type and doing a blank update on the result. Batch class has been scheduled and failing with: Source organization: ****************8(null) Failed to process batch for class 'BatchBlankUpdateCompliance' for job id '7074D00000LzJIL'. Please, can anyone assist me the correct this error?
caused by: System.QueryException: Variable does not exist: Label.PSG_Compliance_Record_Type
Class.BatchBlankUpdateCompliance.start: line 7, column 1
global class BatchBlankUpdateCompliance implements
Database.Batchable<sObject>, Database.Stateful {
// instance member to retain state across transactions
global Integer recordsProcessed = 0;
global Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator(
'SELECT ID FROM Compliance__c ' +
'Where RecordTypeId =: Label.CustomObject_Record_Type'
);
}
global void execute(Database.BatchableContext bc, List<Compliance__c> scope){
// process each batch of records
List<Compliance__c> compList = New List<Compliance__c>();
for (Compliance__c comp : scope) {
compList.add(comp);
recordsProcessed = recordsProcessed + 1;
}
update compList;
}
global void finish(Database.BatchableContext bc){
System.debug(recordsProcessed + ' records processed. Shazam!');
I have a batch class where I am using the custom label to limit result by record type and doing a blank update on the result. Batch class has been scheduled and failing with: Source organization: ****************8(null) Failed to process batch for class 'BatchBlankUpdateCompliance' for job id '7074D00000LzJIL'. Please, can anyone assist me the correct this error?
caused by: System.QueryException: Variable does not exist: Label.PSG_Compliance_Record_Type
Class.BatchBlankUpdateCompliance.start: line 7, column 1
global class BatchBlankUpdateCompliance implements
Database.Batchable<sObject>, Database.Stateful {
// instance member to retain state across transactions
global Integer recordsProcessed = 0;
global Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator(
'SELECT ID FROM Compliance__c ' +
'Where RecordTypeId =: Label.CustomObject_Record_Type'
);
}
global void execute(Database.BatchableContext bc, List<Compliance__c> scope){
// process each batch of records
List<Compliance__c> compList = New List<Compliance__c>();
for (Compliance__c comp : scope) {
compList.add(comp);
recordsProcessed = recordsProcessed + 1;
}
update compList;
}
global void finish(Database.BatchableContext bc){
System.debug(recordsProcessed + ' records processed. Shazam!');

- Sunny Solanki 11
- July 16, 2018
- Like
- 0