-
ChatterFeed
-
0Best Answers
-
1Likes Received
-
0Likes Given
-
5Questions
-
3Replies
delete opportunity product line items
-
- Bruce Hanson
- August 05, 2017
- Like
- 0
- Continue reading or reply
Apex governor limit warning
Assuming I'm right, the trigger below is the culprit. In short, its simple purpose is to set the account record type based on a custom formula field that derives its values from a custom picklist field. The trigger works just as I expect it to. However, when I try to use API tools like dataloader, I get the governor limit warnings. I have it set up to send me an email until I get it solved. If possible, please give guidance on how I can determine for sure what is the cause, and if you agree the below trigger is the cause, any assistance in 'bulkifying' this trigger is much appreciated.
trigger SET_ACCOUNT_RTYPE_TRIGGER2 on Account (before insert, before update) {
Map<String, Id> typeMap = New Map<String, Id>();
for(RecordType RT: [Select DeveloperName, Id From RecordType Where sObjectType = 'Account']) {
typeMap.put(RT.DeveloperName, RT.Id);
}
for (Account ACT : trigger.new) {
id recid = typeMap.get(ACT.Rtype_FM__c);
recordtype rectype = [select id, developername from recordtype where id=:recid];
ACT.RecordTypeid = rectype.id;
}
}
-
- Bruce Hanson
- July 06, 2015
- Like
- 0
- Continue reading or reply
Set Contact Record type on the initial 'create new' screen
I have a working trigger (see below) that sets the Contact Record Type based on the Record type of the Account record. By design, the contact record type names match the account record type names. The purpose of this design is to use record types/page layouts to contol/filter the available values in a custom pick list field. Although this trigger accurately sets the Contact Record type to the correct value, it does not set it until after the initial contact record is saved. Unfortunatley, I need it to be set and be in effect when the initial 'create new contact record' screen appears. If working properly, the inital screen would take into affect the controls/filters as defined for that specific record type. I had assumed that the trigger setting of 'before insert, before update' would meet my requirement but it does not. Can anyone help with this or am I asking for something that is not possible. I'm aware that I can use User Profiles to control the default record type, but that is not really a good solution for me. Any advice and insight is greatly appreciated!
Thanks,
Bruce
trigger SET_CON_RTYPE on Contact(before insert, before update)
{
List<RecordType> C_rtypes = [Select Name, Id From RecordType where sObjectType='Contact' and isActive=true];
Map<String,RecordType> mapContactRecordTypes = new Map<String,RecordType>{};
for(RecordType C_RTY: C_rtypes)
{
mapContactRecordTypes.put(C_RTY.Name,C_RTY);
}
Set<String> setAccID = new Set<String>();
for (Contact THIS_CON : trigger.new)
{
setAccID.add(THIS_CON.accountid);
}
Map<Id,Account> MapAccount = new Map<id,Account>( [Select id,RecordType.Name,recordTypeId from account where id in :setAccID ] );
for (Contact THIS_CON : trigger.new)
{
if(MapAccount.containsKey(THIS_CON.accountId))
{
Account acc = MapAccount.get(THIS_CON.accountId);
if(mapContactRecordTypes.containsKey(acc.RecordType.Name))
{
THIS_CON.recordTypeId = mapContactRecordTypes.get(acc.RecordType.Name).id;
} } } }
-
- Bruce Hanson
- June 28, 2015
- Like
- 0
- Continue reading or reply
Set CONTACT record type based on ACCOUNT record type
trigger SET_CON_RTYPE on Contact(before insert, before update){
//Query for the Account record types
List<RecordType> A_rtypes = [Select Name, Id From RecordType
where sObjectType='Account' and isActive=true];
//Create a map between the Record Type Name and Id for easy retrieval
Map<String,String> A_RecordTypes = new Map<String,String>{};
for(RecordType A_RTY: A_rtypes)
A_RecordTypes.put(A_RTY.Name,A_RTY.Id);
//Query for the Contact record types
List<RecordType> C_rtypes = [Select Name, Id From RecordType
where sObjectType='Contact' and isActive=true];
//Create a map between the Record Type Name and Id for easy retrieval
Map<String,String> C_RecordTypes = new Map<String,String>{};
for(RecordType C_RTY: C_rtypes)
C_RecordTypes.put(C_RTY.Name,C_RTY.Id);
for (Contact THIS_CON : trigger.new) {
if(THIS_CON.Account_Rtype_F__c==A_RecordTypes.get('Agency')){
THIS_CON.RecordTypeid = C_RecordTypes.get('Agency');
} else
if(THIS_CON.Account_Rtype_F__c==A_RecordTypes.get('BodyShop')){
THIS_CON.RecordTypeid = C_RecordTypes.get('BodyShop');
} else
if(THIS_CON.Account_Rtype_F__c==A_RecordTypes.get('Rental')){
THIS_CON.RecordTypeid = C_RecordTypes.get('Rental');
} else {
THIS_CON.RecordTypeid = C_RecordTypes.get('Other');
}
}
}
-
- Bruce Hanson
- June 26, 2015
- Like
- 1
- Continue reading or reply
set picklist value to value from another text field
Using workflow would take too many rules because I need a new rule for each possible value.
Thanks!
-
- Bruce Hanson
- March 10, 2015
- Like
- 0
- Continue reading or reply
Set CONTACT record type based on ACCOUNT record type
trigger SET_CON_RTYPE on Contact(before insert, before update){
//Query for the Account record types
List<RecordType> A_rtypes = [Select Name, Id From RecordType
where sObjectType='Account' and isActive=true];
//Create a map between the Record Type Name and Id for easy retrieval
Map<String,String> A_RecordTypes = new Map<String,String>{};
for(RecordType A_RTY: A_rtypes)
A_RecordTypes.put(A_RTY.Name,A_RTY.Id);
//Query for the Contact record types
List<RecordType> C_rtypes = [Select Name, Id From RecordType
where sObjectType='Contact' and isActive=true];
//Create a map between the Record Type Name and Id for easy retrieval
Map<String,String> C_RecordTypes = new Map<String,String>{};
for(RecordType C_RTY: C_rtypes)
C_RecordTypes.put(C_RTY.Name,C_RTY.Id);
for (Contact THIS_CON : trigger.new) {
if(THIS_CON.Account_Rtype_F__c==A_RecordTypes.get('Agency')){
THIS_CON.RecordTypeid = C_RecordTypes.get('Agency');
} else
if(THIS_CON.Account_Rtype_F__c==A_RecordTypes.get('BodyShop')){
THIS_CON.RecordTypeid = C_RecordTypes.get('BodyShop');
} else
if(THIS_CON.Account_Rtype_F__c==A_RecordTypes.get('Rental')){
THIS_CON.RecordTypeid = C_RecordTypes.get('Rental');
} else {
THIS_CON.RecordTypeid = C_RecordTypes.get('Other');
}
}
}
-
- Bruce Hanson
- June 26, 2015
- Like
- 1
- Continue reading or reply
delete opportunity product line items
- Bruce Hanson
- August 05, 2017
- Like
- 0
- Continue reading or reply
Set Contact Record type on the initial 'create new' screen
I have a working trigger (see below) that sets the Contact Record Type based on the Record type of the Account record. By design, the contact record type names match the account record type names. The purpose of this design is to use record types/page layouts to contol/filter the available values in a custom pick list field. Although this trigger accurately sets the Contact Record type to the correct value, it does not set it until after the initial contact record is saved. Unfortunatley, I need it to be set and be in effect when the initial 'create new contact record' screen appears. If working properly, the inital screen would take into affect the controls/filters as defined for that specific record type. I had assumed that the trigger setting of 'before insert, before update' would meet my requirement but it does not. Can anyone help with this or am I asking for something that is not possible. I'm aware that I can use User Profiles to control the default record type, but that is not really a good solution for me. Any advice and insight is greatly appreciated!
Thanks,
Bruce
trigger SET_CON_RTYPE on Contact(before insert, before update)
{
List<RecordType> C_rtypes = [Select Name, Id From RecordType where sObjectType='Contact' and isActive=true];
Map<String,RecordType> mapContactRecordTypes = new Map<String,RecordType>{};
for(RecordType C_RTY: C_rtypes)
{
mapContactRecordTypes.put(C_RTY.Name,C_RTY);
}
Set<String> setAccID = new Set<String>();
for (Contact THIS_CON : trigger.new)
{
setAccID.add(THIS_CON.accountid);
}
Map<Id,Account> MapAccount = new Map<id,Account>( [Select id,RecordType.Name,recordTypeId from account where id in :setAccID ] );
for (Contact THIS_CON : trigger.new)
{
if(MapAccount.containsKey(THIS_CON.accountId))
{
Account acc = MapAccount.get(THIS_CON.accountId);
if(mapContactRecordTypes.containsKey(acc.RecordType.Name))
{
THIS_CON.recordTypeId = mapContactRecordTypes.get(acc.RecordType.Name).id;
} } } }
- Bruce Hanson
- June 28, 2015
- Like
- 0
- Continue reading or reply
Set CONTACT record type based on ACCOUNT record type
trigger SET_CON_RTYPE on Contact(before insert, before update){
//Query for the Account record types
List<RecordType> A_rtypes = [Select Name, Id From RecordType
where sObjectType='Account' and isActive=true];
//Create a map between the Record Type Name and Id for easy retrieval
Map<String,String> A_RecordTypes = new Map<String,String>{};
for(RecordType A_RTY: A_rtypes)
A_RecordTypes.put(A_RTY.Name,A_RTY.Id);
//Query for the Contact record types
List<RecordType> C_rtypes = [Select Name, Id From RecordType
where sObjectType='Contact' and isActive=true];
//Create a map between the Record Type Name and Id for easy retrieval
Map<String,String> C_RecordTypes = new Map<String,String>{};
for(RecordType C_RTY: C_rtypes)
C_RecordTypes.put(C_RTY.Name,C_RTY.Id);
for (Contact THIS_CON : trigger.new) {
if(THIS_CON.Account_Rtype_F__c==A_RecordTypes.get('Agency')){
THIS_CON.RecordTypeid = C_RecordTypes.get('Agency');
} else
if(THIS_CON.Account_Rtype_F__c==A_RecordTypes.get('BodyShop')){
THIS_CON.RecordTypeid = C_RecordTypes.get('BodyShop');
} else
if(THIS_CON.Account_Rtype_F__c==A_RecordTypes.get('Rental')){
THIS_CON.RecordTypeid = C_RecordTypes.get('Rental');
} else {
THIS_CON.RecordTypeid = C_RecordTypes.get('Other');
}
}
}
- Bruce Hanson
- June 26, 2015
- Like
- 1
- Continue reading or reply