• Uttpal_Chandra
  • NEWBIE
  • 145 Points
  • Member since 2019

  • Chatter
    Feed
  • 5
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 36
    Replies
Hello Everyone

I am new to the Apex development, i have Developed a Trigger where a custom field is updated based on the Formula field(Region), i have designed a trigger and its working perfectly, but the thing is i have written 5 seperate SOQL queries, so when i save a record it queries 5 times, How do i bulkify the trigger, so that it should query only once

Any Help will be Appricated

trigger Increment on Lead (before insert,Before Update) {
    if(trigger.isBefore && (trigger.isInsert || trigger.isUpdate || Trigger.IsUnDelete))  {
        List<Lead> leadList = [Select Id,PraticeLWC__Lead_No_Region_IN__c From Lead Where PraticeLWC__Region__c = 'India'];
        For(Lead l : trigger.New ) {
            if(l.PraticeLWC__Region__c == 'India') {
                if(leadList.size() > 0){
                    l.PraticeLWC__Lead_No_Region_IN__c = leadList.size()+0;
                } else {
                    l.PraticeLWC__Lead_No_Region_IN__c = 1;
                }
            }
        }
        List<Lead> leadListt = [Select Id,PraticeLWC__Lead_No_Region_USA__c From Lead Where PraticeLWC__Region__c = 'US'];
        For(Lead m : trigger.New) {
            if(m.PraticeLWC__Region__c == 'US') {
                if(leadListt.size() > 0){
                    m.PraticeLWC__Lead_No_Region_USA__c = leadListt.size()+0;   
                } else {
                    m.PraticeLWC__Lead_No_Region_USA__c = 1;
                }
            }
        } 
        List<Lead> leadListm = [Select Id,PraticeLWC__Lead_No_Region_EU__c From Lead Where PraticeLWC__Region__c = 'EU'];
        For(Lead n : trigger.New) {
            if(n.PraticeLWC__Region__c == 'EU') {
                if(leadListm.size() > 0){
                    n.PraticeLWC__Lead_No_Region_EU__c = leadListm.size()+0;   
                } else {
                    n.PraticeLWC__Lead_No_Region_EU__c = 1;
                }
            }
        } 
        List<Lead> leadListo = [Select Id,PraticeLWC__Lead_No_Region_SEA__c From Lead Where PraticeLWC__Region__c = 'SEA'];
        For(Lead o : trigger.New) {
            if(o.PraticeLWC__Region__c == 'SEA') {
                if(leadListo.size() > 0){
                    o.PraticeLWC__Lead_No_Region_SEA__c = leadListo.size()+0;   
                } else {
                    o.PraticeLWC__Lead_No_Region_SEA__c = 1;
                }
            }
        }
        List<Lead> leadListp = [Select Id,PraticeLWC__Lead_No_Region_ME__c From Lead Where PraticeLWC__Region__c = 'ME'];
        For(Lead p : trigger.New) {
            if(p.PraticeLWC__Region__c == 'ME') {
                if(leadListp.size() > 0){
                    p.PraticeLWC__Lead_No_Region_ME__c = leadListp.size()+0;   
                } else {
                    p.PraticeLWC__Lead_No_Region_ME__c = 1;
                }
            }
        } 
        
    }                   
}
im currently writing a trigger to send an email to the account owner, when a contact is deleted,  I am almost there,  can anyone point out where i am going wrong.  Also how do i write a test class for this?  Here is what i have so far I copied this and changed it to what i was needing,  but don't know how to reference the account owner email and where it goes,  is it owner.email?

trigger EmailAfterDelete on Contact (after delete) {
Messaging.reserveSingleEmailCapacity(trigger.size);
    List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
    for (Contact Contact : Trigger.old) {
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        email.setToAddresses(new String[] {'some email address'};);
        email.setSubject('Deleted Contact Alert');
        email.setPlainTextBody('This message is to alert you that the Contact named ' + Contact.Name +' on Account' + Account.Name +
                               ' has been deleted.');
        emails.add(email);
    }
    Messaging.sendEmail(emails);

}
Hello,

i am executing a code in anonymouse log
I have a error like below
System.LimitException: Apex heap size too large: 6046577

i am executing a SOQL query,
What alternative code i can i use,
thank you
  • January 31, 2020
  • Like
  • 0
Hi Master developers,
  I am an Admin at a non-profit with newbie to development and need your help! I am trying to deploy a small change from Sandbox to Production , but faced with 'dependent class is invalid and needs recompilation' for all my Apex classes. The change I did was - on a Schedulable batch job ,I removed the insert statement from Finish method to the execute method as I was getting the system limit exception DML rows >10001 (old code , but may be we have too many records now).

My code below -
global void checkCollege(ID college,ID studentID){
        CommunitiesUserPermissionService.ContactShareMatch existingContactSharingRule = null;
        if(existingGroupSharingRulesMap.get(groupMap.get('grp_' + college).Id) != null) {
            existingContactSharingRule = existingGroupSharingRulesMap.get(groupMap.get('grp_' + college).Id).get(studentID);
        }
        
        if (existingContactSharingRule == null) {
            system.debug('making sharing rule');
            ContactShare cs = new ContactShare();
            cs.contactAccessLevel = 'Edit';
            cs.userOrGroupId = groupMap.get('grp_' + college).Id;
            cs.contactId = studentID;
            csList.add(cs);
            CommunitiesUserPermissionService.ContactShareMatch csm = new CommunitiesUserPermissionService.ContactShareMatch();
            csm.matchFound = true;
            csm.rule = cs;
            if(existingGroupSharingRulesMap.get(groupMap.get('grp_' + college).Id) == null) {
                existingGroupSharingRulesMap.put(groupMap.get('grp_' + college).Id, new Map<Id,CommunitiesUserPermissionService.ContactShareMatch>());
            }
            existingGroupSharingRulesMap.get(groupMap.get('grp_' + college).Id).put(studentID, csm);
        } else {
            existingContactSharingRule.matchFound = true;
            System.debug('Existing Rule ' + existingContactSharingRule);
        }
    }
         
    global void execute(Database.BatchableContext BC, List<Application__c> scope) {
        for (Application__c ap : scope) {
            // check school_name and Mid_Year_transfer, each calling the same method.
            // 
            System.debug('School Name: '+ap.School_Name__c+', groupMap get result: '+groupMap.get('grp_' + ap.School_Name__c));
            if (ap.School_Name__c != null && groupMap.get('grp_' + ap.School_Name__c) != null) {
                checkCollege(ap.School_Name__c,ap.student_name__c);
            }
            System.debug('School Name: '+ap.Mid_Year_Transfer_School__c+', groupMap get result: '+
                         groupMap.get('grp_' + ap.Mid_Year_Transfer_School__c));
            if (ap.Mid_Year_Transfer_School__c != null && ap.Mid_Year_Transfer_Status__c == 'Approved' && 
              groupMap.get('grp_' + ap.Mid_Year_Transfer_School__c) != null) {
                checkCollege(ap.Mid_Year_Transfer_School__c,ap.student_name__c);
            }
            
        }
        system.debug('cslist' +  csList);
        if (!csList.isEmpty()) insert csList;     
        cslist.clear();        - Changes here , so that the data is inserted every time the batch is processed and we dont hit the DML limit exception

        
    }

    global void finish(Database.BatchableContext BC) {
        //System.debug(csList);
        //if (! csList.isEmpty()) insert csList;   -Moved this to the execute batch method to resolve the DML system limit exception error
    }




After fixing this , the code ran successfully in Full sandbox but when I deploy I see this error. 
User-added image

Any input is greatly appreciated. 
Thanks!
I am getting this error when using ANT.

UserName:lwcdx@lwcdx.com
Password:Test@123

"Invalid username, password, security token; or user locked out"

Plz help
Hi all,

I got a Stored XSS  error in the wrapper class method and I am using the wrapper class variable on the VF page in apex:repeat.

Anyone know why it is happening...??
Hi ,

Anyone knows how to write cron expression for every 1 minute..??
Hi all,

I got a Stored XSS  error in the wrapper class method and I am using the wrapper class variable on the VF page in apex:repeat.

Anyone know why it is happening...??
I have written a test class to add all amount on quota which lies between start and end date of quota

I am getting below error

User-added image

Test class
@isTest
public class Test_listopponquota {
    static testMethod void listopponquota(){
        
        Quota__c a = new  Quota__c(Name = 'Test');
        a.Assign_to_User__c = 'Shruthi MN';
        a.Start_Date__c = date.today();
         a.Start_Date__c = date.today() + 12;
        insert a;
        
        
        Opportunity o = new Opportunity();
        o.name = 'Test';
        o.StageName = 'Closed Won';
        o.CloseDate = date.today();
        o.Type = 'New Customers';
        
        insert o;
    }
   
}
apex
public with sharing class listopponquota {
     
    
    public list<Opportunity> oppList{get;set;}
    public list<quota__c> qutoaList{get;set;}
    public set<ID> oppIds = new set<ID>(); 
    
    public listopponquota()
    {
        String selectedVal ='';
        oppList = new list<Opportunity>();
        qutoaList = new list<quota__c>();
        oppList();
    }
    
    public pageReference oppList() {
        Id qId = (Id) ApexPages.currentPage().getParameters().get('id');
        system.debug('Id-->'+qId);    
        List<quota__c> quotaList1 = new List<quota__c>();
        List<Opportunity> oppList1 = new List<Opportunity>();
        
        quotaList1 =[select Id, Name,Start_Date__c,End_Date__c,Assign_to_User__c,Actual_Amount__c, OwnerId from quota__c where Id   =: qId Limit 1];
        oppList1 = [Select Id, Name, CloseDate, StageName,OwnerId,Amount From Opportunity where StageName = 'Closed Won'];
        
        system.debug('quotaList1-->'+quotaList1);
        if(quotaList1.size() > 0){
            for(quota__c q : quotaList1){
                
                for(Opportunity opp : oppList1){
                    system.debug('closedDate-->'+opp.CloseDate);
                    if(opp.CloseDate  >=  q.Start_Date__c  && opp.CloseDate <= q.End_Date__c && q.Assign_to_User__c == q.OwnerId){
                        oppList.add(opp);
                        oppIds.add(opp.id);
                    } 
                }                
            }
        }
        for(aggregateresult ag : [SELECT SUM(Amount) sum FROM Opportunity where ID =:oppIds]){
            system.debug('oppList-->'+double.valueof(ag.get('SUM')));
            for(quota__c q : quotaList1){
                if(q.Actual_Amount__c != double.valueof(ag.get('SUM'))){
                    q.Actual_Amount__c = double.valueof(ag.get('SUM'));
                    qutoaList.add(q);
                     System.enqueueJob(q);
                }
            }
        }
        system.debug('oppList-->'+oppList.size());
        return null;
    }
    
    public void doCallout(){
        system.debug('qutoaList-->'+qutoaList.size());
        if(qutoaList.size()>0){
            update qutoaList;
        }
        
    }
}

Vf

<apex:page controller="listopponquota" lightningStylesheets="true" action="{!doCallout}">
    <apex:form > 
        <apex:pageBlock rendered="true" >
            <apex:pageBlockTable value="{!oppList}" var="v">
                <apex:column value="{!v.OwnerId}"/>
                
                <apex:column headerValue="Opportunity Name">
                    <apex:outputlink value="/{!v.Id}">{!v.Name}</apex:outputlink>
                </apex:column>
                <apex:column value="{!v.CloseDate}"/>
                <apex:column value="{!v.StageName}"/>
                <apex:column value="{!v.Amount}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form> 
</apex:page
I have created a schedular class but it is not showing while trying to schedule it through UI.

Please find below batch and schedular class :
Batch Class:
public class deletePendingServiceReq implements Database.Batchable<sObject>{
    public static Date lastYear = Date.today().addMonths(-10);
    public static string statusVal='Pending';
    public Database.QueryLocator start(Database.BatchableContext context)
    {
        return Database.getQueryLocator('Select ID,createdDate,MUSW__Status__c from MUSW__Application2__c where CreatedDate < :lastYear and MUSW__Status__c=:statusVal');
    }

    public void execute(Database.BatchableContext context, List<SObject> records)
    {
        //System.debug('records to be deleted'+records);
        delete records;
    }
    
    public void finish(Database.BatchableContext BC){}   
}

Schedular:
public class deletePendingServiceReqSchedular implements Schedulable {
    
     public void execute(SchedulableContext ctx) 
    {
        Database.executeBatch(new deletePendingServiceReq());
    }

}

It is working if I am scheduling it through developer console:
System.schedule('Scheduled Job 1', '0 54 * * * ?', new deletePendingServiceReqSchedular());

But it is not showing in list of schedulable class when I am trying to schedule it through UI. 
I am system admin.
SetUp-->Apex Class-->Schedule Class
User-added image
Hello,
Do not understand why my filed is not rendering when the condiion is met.
<apex:pageBlockSection showHeader="true" rendered="true" columns="1" id="section">
                <apex:inputField required="true" value="{!Drawing__c.Wireless_Fiber__c}"/>  
                <apex:inputField id="proj" value="{!Drawing__c.Project__c}" rendered="{!IF(Drawing__c.Wireless_Fiber__c = 'Wireless',true,false)}"/>

So if the picklist value is wireless I thought the Drawing__c.Project__c would render but it does not. 
What am I doing wrong?

Thanks,
P
I was unable to complete a trailhead task in Admin Beginner-> Salesforce Mobile App Customization -> Customize Compact Layouts..
I have created a Compact Layout in my Developer Environment but I am still getting the following error..


Challenge not yet complete in maddulasaivineeth@bigworks.com
There was an unexpected error while verifying this challenge. Usually this is due to some pre-existing configuration or code in the challenge Org. We recommend using a new Developer Edition (DE) to check this challenge. If you're using a new DE and seeing this error, please post to the developer forums and reference error id: ZFEQRJTP
  • February 06, 2020
  • Like
  • 0
Hello
I am trying to send an email to all the Owners of Opportunities when those Opportunities are 90 days from closing.
I have a custom field called "Days til Close" and I have an email template and a email alert setup.

I need to know how to
1) schedule query that looks up all the Opportunities that have 90 in the "days to close" field
2) run a flow or trigger an email alert to fire.

Does anyone know how to do this?  

Thank you,
Nicole
Hello
On a custom object we have a lookup field "Rep" that is related to "User" object. 
I would like to filter that field to only show the current user. 

Below is the Lookup Filter I applied but is does not bring back any values in the list. Any help would be appreciated ==>

Filter CriteriaRep: User IDequalsCurrent User: User ID
Filter TypeRequired. The user-entered value must match filter criteria.
Hello Everyone

I am new to the Apex development, i have Developed a Trigger where a custom field is updated based on the Formula field(Region), i have designed a trigger and its working perfectly, but the thing is i have written 5 seperate SOQL queries, so when i save a record it queries 5 times, How do i bulkify the trigger, so that it should query only once

Any Help will be Appricated

trigger Increment on Lead (before insert,Before Update) {
    if(trigger.isBefore && (trigger.isInsert || trigger.isUpdate || Trigger.IsUnDelete))  {
        List<Lead> leadList = [Select Id,PraticeLWC__Lead_No_Region_IN__c From Lead Where PraticeLWC__Region__c = 'India'];
        For(Lead l : trigger.New ) {
            if(l.PraticeLWC__Region__c == 'India') {
                if(leadList.size() > 0){
                    l.PraticeLWC__Lead_No_Region_IN__c = leadList.size()+0;
                } else {
                    l.PraticeLWC__Lead_No_Region_IN__c = 1;
                }
            }
        }
        List<Lead> leadListt = [Select Id,PraticeLWC__Lead_No_Region_USA__c From Lead Where PraticeLWC__Region__c = 'US'];
        For(Lead m : trigger.New) {
            if(m.PraticeLWC__Region__c == 'US') {
                if(leadListt.size() > 0){
                    m.PraticeLWC__Lead_No_Region_USA__c = leadListt.size()+0;   
                } else {
                    m.PraticeLWC__Lead_No_Region_USA__c = 1;
                }
            }
        } 
        List<Lead> leadListm = [Select Id,PraticeLWC__Lead_No_Region_EU__c From Lead Where PraticeLWC__Region__c = 'EU'];
        For(Lead n : trigger.New) {
            if(n.PraticeLWC__Region__c == 'EU') {
                if(leadListm.size() > 0){
                    n.PraticeLWC__Lead_No_Region_EU__c = leadListm.size()+0;   
                } else {
                    n.PraticeLWC__Lead_No_Region_EU__c = 1;
                }
            }
        } 
        List<Lead> leadListo = [Select Id,PraticeLWC__Lead_No_Region_SEA__c From Lead Where PraticeLWC__Region__c = 'SEA'];
        For(Lead o : trigger.New) {
            if(o.PraticeLWC__Region__c == 'SEA') {
                if(leadListo.size() > 0){
                    o.PraticeLWC__Lead_No_Region_SEA__c = leadListo.size()+0;   
                } else {
                    o.PraticeLWC__Lead_No_Region_SEA__c = 1;
                }
            }
        }
        List<Lead> leadListp = [Select Id,PraticeLWC__Lead_No_Region_ME__c From Lead Where PraticeLWC__Region__c = 'ME'];
        For(Lead p : trigger.New) {
            if(p.PraticeLWC__Region__c == 'ME') {
                if(leadListp.size() > 0){
                    p.PraticeLWC__Lead_No_Region_ME__c = leadListp.size()+0;   
                } else {
                    p.PraticeLWC__Lead_No_Region_ME__c = 1;
                }
            }
        } 
        
    }                   
}
 If amount is greater than 10000 then stage should allow closed won other wise throw an error, on opportunity
  • February 03, 2020
  • Like
  • 0
im currently writing a trigger to send an email to the account owner, when a contact is deleted,  I am almost there,  can anyone point out where i am going wrong.  Also how do i write a test class for this?  Here is what i have so far I copied this and changed it to what i was needing,  but don't know how to reference the account owner email and where it goes,  is it owner.email?

trigger EmailAfterDelete on Contact (after delete) {
Messaging.reserveSingleEmailCapacity(trigger.size);
    List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
    for (Contact Contact : Trigger.old) {
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        email.setToAddresses(new String[] {'some email address'};);
        email.setSubject('Deleted Contact Alert');
        email.setPlainTextBody('This message is to alert you that the Contact named ' + Contact.Name +' on Account' + Account.Name +
                               ' has been deleted.');
        emails.add(email);
    }
    Messaging.sendEmail(emails);

}
Hi all,

Is there any way where I can check if there is any open opportunity with the close date is in past and if it is there tehn I want to close it before i create a new opportunity on the same account.
Here I am creating the new opportunity using the batch job and my job will run on first day of every month.
Thanks in advance........
Hello,

i am executing a code in anonymouse log
I have a error like below
System.LimitException: Apex heap size too large: 6046577

i am executing a SOQL query,
What alternative code i can i use,
thank you
  • January 31, 2020
  • Like
  • 0
Hi Folks ,
I have tryingg to move with this challenge from a long time but not able to complete it .Due to which my other challenges are not done .Please help me out.

Data Flow-Load Seed Bank Agencies
{
  "Filter Agency Records": {
    "action": "filter",
    "parameters": {
      "filter": "IsAgency:EQ:TRUE",
      "source": "ID Agency Records"
    }
  },
  "Load Account": {
    "action": "sfdcDigest",
    "parameters": {
      "fields": [
        {
          "name": "Name"
        },
        {
          "name": "AccountNumber"
        },
        {
          "name": "Phone"
        },
        {
          "name": "ShippingCity"
        },
        {
          "name": "ShippingCountry"
        },
        {
          "name": "ShippingState"
        },
        {
          "name": "ShippingStreet"
        },
        {
          "name": "ShippingPostalCode"
        }
      ],
      "object": "Account"
    }
  },
  "Remove Agency": {
    "action": "sliceDataset",
    "parameters": {
      "mode": "drop",
      "source": "Filter Agency Records",
      "fields": [
        {
          "name": "IsAgency"
        }
      ]
    }
  },
  "Create Seed Bank Agencies": {
    "action": "sfdcRegister",
    "parameters": {
      "name": "Seed Bank Agencies",
      "alias": "seed_bank_agencies",
      "source": "Remove Agency"
    }
  },
  "Add Agency Fields": {
    "action": "augment",
    "parameters": {
      "right_key": [
        "AccountNumber"
      ],
      "left": "Load Account",
      "left_key": [
        "AccountNumber"
      ],
      "right_select": [
        "Acres",
        "Currency",
        "Longitude",
        "Latitude",
        "Region",
        "SubRegion"
      ],
      "right": "Load Agency Detail",
      "relationship": "AgencyDetail",
      "operation": "LookupSingleValue"
    }
  },
  "Load Agency Detail": {
    "action": "edgemart",
    "parameters": {
      "alias": "Agency_Detail"
    }
  },
  "ID Agency Records": {
    "action": "computeExpression",
    "parameters": {
      "source": "Add Agency Fields",
      "mergeWithSource": true,
      "computedFields": [
        {
          "name": "IsAgency",
          "saqlExpression": "case when Phone is not null then \"TRUE\" else \"FALSE\" end",
          "label": "IsAgency",
          "type": "Text"
        }
      ]
    }
  }
}

Load Seed Bank Agencies DataFlow diagram
Error -
Error at the challenge

I have tried creating a differnt Developers Org also .But the error still remains the same.




 
I am looking for help on a trigger for the case object.
I have three objects Case, Account and a custom object Site_Partner__c

I need help with a trigger or pex class that performs like this:
The Account object has related records from the Site_Partner__c which has a account lokup field Site__c

I need the functionality to perform that when a case record is created the trigger/class finds the Site_Partner__c records associated with the account on the case record and assigns the case ID to the Case___c lookup field on the Site_Partner__c record. I'm just not sure what the best practices solution to this requirement i.e. Trigger, Apex Class or Process builder.
  • January 29, 2020
  • Like
  • 0