You need to sign in to do that
Don't have an account?
The new Learner
how to convert list into map --urgent pls
Hi Experts,
I have below code which is calling before update on account ,i have nested loops because of that i am getting cpu time out issue, can anyone convert my code into MAp please.
Set<Id> Accids= New Set<Id>();
Set<String>Fun= new set<string>();
Id AccRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('RecordType').getRecordTypeId();
if(AccRecordTypeId !=null)
{
FOR(Account A : newList)
{
if(A.RecordTypeId == AccRecordTypeId)
{
Accids.Add(A.id);
system.debug('%%%%%%'+Accids);
}
}
}
String samp = System.Label.User_ID;
List<Function__c> PR = [Select Id,Salesforce_ID__c,Function_Def__c,Person__c,Pernr__c from Function__c where Salesforce_ID__c IN : Accids and Pernr__c !=null ];
system.debug('$$$$$$'+PR );
for(Function__c pf: PR)
{
if( pf.Salesforce_ID__c != Null)
{
system.debug('^^^^^^'+pf);
Fun.add(pf.Pernr__c);
system.debug('#######'+Fun);
}
}
list<Person__c> gp = [ select id , Employee_ID__c,User__c,OwnerId from Person__c where Employee_ID__c in : Fun];
system.debug('@@@@@'+gp );
if(gp.size()>0)
{
FOR(Account A : newList)
{
for(Person__c gpr: gp)
{
for( Function__c pfr: PR)
{
if(gpr.User__c!=null && pfr.Function_Def__c!=null )
{
if(pfr.Function_Def__c== 'ABC' )
{
system.debug('&&&&&'+gpr);
A.OwnerId=gpr.User__c;
system.debug('!!!!!'+A.ownerid);
}
else if(pfr.Function_Def__c== 'DEF' || pfr.Function_Def__c== 'GHI' || pfr.Function_Def__c== 'JKL')
{
A.OwnerId=gpr.User__c;
system.debug('88888'+A.ownerid);
}
}
else
{
A.OwnerId=samp;
system.debug('***'+A.ownerid);
}
}
}
}
}
I have below code which is calling before update on account ,i have nested loops because of that i am getting cpu time out issue, can anyone convert my code into MAp please.
Set<Id> Accids= New Set<Id>();
Set<String>Fun= new set<string>();
Id AccRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('RecordType').getRecordTypeId();
if(AccRecordTypeId !=null)
{
FOR(Account A : newList)
{
if(A.RecordTypeId == AccRecordTypeId)
{
Accids.Add(A.id);
system.debug('%%%%%%'+Accids);
}
}
}
String samp = System.Label.User_ID;
List<Function__c> PR = [Select Id,Salesforce_ID__c,Function_Def__c,Person__c,Pernr__c from Function__c where Salesforce_ID__c IN : Accids and Pernr__c !=null ];
system.debug('$$$$$$'+PR );
for(Function__c pf: PR)
{
if( pf.Salesforce_ID__c != Null)
{
system.debug('^^^^^^'+pf);
Fun.add(pf.Pernr__c);
system.debug('#######'+Fun);
}
}
list<Person__c> gp = [ select id , Employee_ID__c,User__c,OwnerId from Person__c where Employee_ID__c in : Fun];
system.debug('@@@@@'+gp );
if(gp.size()>0)
{
FOR(Account A : newList)
{
for(Person__c gpr: gp)
{
for( Function__c pfr: PR)
{
if(gpr.User__c!=null && pfr.Function_Def__c!=null )
{
if(pfr.Function_Def__c== 'ABC' )
{
system.debug('&&&&&'+gpr);
A.OwnerId=gpr.User__c;
system.debug('!!!!!'+A.ownerid);
}
else if(pfr.Function_Def__c== 'DEF' || pfr.Function_Def__c== 'GHI' || pfr.Function_Def__c== 'JKL')
{
A.OwnerId=gpr.User__c;
system.debug('88888'+A.ownerid);
}
}
else
{
A.OwnerId=samp;
system.debug('***'+A.ownerid);
}
}
}
}
}
Have fun :
Please choose best answer if your problem has been resolved,
GrumpyDev.
All Answers
Have fun :
Please choose best answer if your problem has been resolved,
GrumpyDev.
dont we get CPU time out issue again if anyone do an data load we wrote two for loops here that is the reason
I dont know what happens before and after the snippet you added.
But if nothing crazy goes before or after this should work even when using Data Loader.
If you will get a CPU time out after replacing your code with mine I can only guess this is not where it fails.
GrumpyDev.