• Alex Rana
  • NEWBIE
  • -1 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    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 all! I'm really new to apex code, trying to figure out how to get related records from Account. Any help is appreciated!

VF page:
<apex:page Controller="UseofRepeatOnEpudsController">
<apex:form >
    <apex:pageBlock title="Accounts with assoicated Contacts">
        <apex:repeat value="{!epudsList }" var="epd">
            <apex:pageBlockSection title="{!epd.name} - {!epd.Account1__r.Name}">
                <apex:pageBlockTable value="{!epudsList}" var="epd2">
                    <apex:column value="{!epd2.Absorbent_drum_1__c}"/>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
        </apex:repeat>
    </apex:pageBlock>
    </apex:form>
</apex:page>

Controller:
public class UseofRepeatOnEpudsController {
    public List<Logistic__c> epudsList{get;set;}
    public List<Account> AccountList{get;set;}
    public Id accId{get;set;}
    
    public UseofRepeatOnEpudsController() {
        accId = ApexPages.CurrentPage().getparameters().get('Id');
        epudsList = new List<Logistic__c>();
        epudsList = [SELECT id, Name ,  Account1__R.Name, Absorbent_drum_1__c From Logistic__c where Account1__c =:accId] ;
        accountList = [SELECT id, Name From Account];
    }

​Result:
I can't select VF page when setting up a button. My guess is that I need to use Standard controller="Account" and extention (My controller). I'm not sure how to set it correctly. Getting errors.

Also, epudsList is showing related custom object names which is fine, but PageBlockTable will show records not per custom object reocord - but all custom object records together.

So basically I'd like to press button on account and get related records separated. Accoont - > List of custom object records -> (Values related to one record)

Now its showing like: Account -> List of custom object records -> (Values related to multiple records) which is wrong.

Thanks for helping me out!
How can i ignore the www. for not showing an error example (www.yahoo.com = yahoo.com; www.cs.org != www.cs.ph)
here is duplication method for my website. Thanks in advance

public static void checkDuplicateWebsite(List<Account> newRecord){
       for(Account a: newRecord){
           List<Account> account = [SELECT Id, Website FROM Account WHERE Website=:a.Website];
           if(account.size()>0){
               a.adderror('You cannot create a duplicate Website');
           }       
    }

On the Account object I have created a formula field called Domain_Name__c . The formula I have used is this,

 

SUBSTITUTE(Website, LEFT(Website, FIND("www.", Website)), NULL)

 

Where website is a standard field on Account.

 

If Website is www.xyzdomain.com or https://www.xyzdomain.com

 

In Domain_Name__c I expected result as xyzdomain.com

 

Instead i am getting the result either as

.xyzdomain.com or ww.xyzdomain.com depending on whether the Email entered was 'www.xyzdomain.com' or 'https://www.xyzdomain.com'


Any thoughts how I can only get the text after the .   

 

e.g If, in the field Website  I enter www.salesforce.com  or  https://www.salesforce.com the result in the Domain_Name__c should be salesforce.com