• Alessandro Patricelli
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 8
    Replies
Hi everyone.
I just wrote this trigger that helps me to update some fields based on records of my custom metadata types.

My friend is telling me that my code would hit SOQL Query limits... so it's bad and i must try to find a new way to write this code.
I just checked on help.salesforce.com 
--> https://help.salesforce.com/articleView?id=custommetadatatypes_limits.htm&type=5

and it says : 
SOQL queries per Apex transaction Unlimited

This is my code:
trigger ProfitOfferInsert on Quote (before update, before insert) 
{
	EX__mdt[] metaList = [SELECT Business_Unit__c, OfferType__c, ProfitCenter__c, Soluzione__c, Tipo__c FROM EX__mdt];

	for(Quote q : Trigger.new) 
	{	
		for(EX__mdt e : metaList)
		{
			if(q.Business_Unit__c == e.Business_Unit__c && q.Tipo__c == e.Tipo__c && q.Soluzione__c == e.Soluzione__c) 
			{
				q.Profit_Center__c = e.ProfitCenter__c;
                q.OfferType__c = e.ProfitCenter__c;
			}
		}
	}
    
}

So, what do you think guys ? Will this code Hit SOQL Query Limits or not?

P.S: Inside my custom metadata type we have only 25 records but maybe in future this number will increase.
Thanks in advance
Hi everyone.
I just wrote this trigger that helps me to update some fields based on records of my custom metadata types.

My friend is telling me that my code would hit SOQL Query limits... so it's bad and i must try to find a new way to write this code.
I just checked on help.salesforce.com 
--> https://help.salesforce.com/articleView?id=custommetadatatypes_limits.htm&type=5

and it says : 
SOQL queries per Apex transaction Unlimited

This is my code:
trigger ProfitOfferInsert on Quote (before update, before insert) 
{
	EX__mdt[] metaList = [SELECT Business_Unit__c, OfferType__c, ProfitCenter__c, Soluzione__c, Tipo__c FROM EX__mdt];

	for(Quote q : Trigger.new) 
	{	
		for(EX__mdt e : metaList)
		{
			if(q.Business_Unit__c == e.Business_Unit__c && q.Tipo__c == e.Tipo__c && q.Soluzione__c == e.Soluzione__c) 
			{
				q.Profit_Center__c = e.ProfitCenter__c;
                q.OfferType__c = e.ProfitCenter__c;
			}
		}
	}
    
}

So, what do you think guys ? Will this code Hit SOQL Query Limits or not?

P.S: Inside my custom metadata type we have only 25 records but maybe in future this number will increase.
Thanks in advance