• Maharajan C
  • ALL STAR
  • 16444 Points
  • Member since 2015
  • Consultant
  • Infosys


  • Chatter
    Feed
  • 529
    Best Answers
  • 4
    Likes Received
  • 60
    Likes Given
  • 15
    Questions
  • 1747
    Replies
I need to show 'no records available' as a table results if I didn't receive any record
Question :To Show The Total Number Of Active Child Contacts On A Parent Account.

**Issue : For Bulk Operations I  am getting an error ‘First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ContactTrigger: execution of AfterInsert’**

•    Contact Object Has A Custom Field (checkbox) called “Active”.
•    Account Object Has A Custom Field (number) called “Active Contacts”.


**Code Written:**

    public class ContactTriggerHandler {
    public static void countOfActiveContacts(List<Contact> lstContact){
        Set<Id> setAccId=new Set<Id>(); 
        List<Account> lstAccount=new List<Account>();
        
        If(lstContact!=null){
            For(Contact cont:lstContact){
                setAccId.add(cont.AccountId);
            }}
        If(setAccId!=null){
            For(Account acc:[SELECT Id,Active_Contacts__c,(SELECT AccountId,Id,Active__c FROM Contacts WHERE Active__c =True) FROM Account WHERE Id IN:setAccId]){
                acc.Active_Contacts__c=acc.Contacts.size();
                lstAccount.add(acc);
            }
        }
        Update lstAccount;
    }

}



**My Test Calss Code:**

  

      @isTest
private class ContactTriggerHandlerTest  {
    @isTest static void countOfActiveContactsBulk() {

        Account acct = new Account(Name='Test Account');
        insert acct;
        List<Contact> lstCont= New List<Contact>();
        for(Integer i=0;i<200;i++) 
        {
            
            Contact cont= new Contact(LastName='cont'+i,
                          AccountId=acct.Id,
                                      Active__c=True);
            lstCont.add(cont)
        }
        
        test.startTest();
        insert lstCont;
        update acct;
        test.stopTest();
        
      system.assertEquals(acct.Active_Contacts__c,200);  

}



 
I am gettinf the output of month as number . but i need to convert that as string. can anyone help me?

​​​​​​​public with sharing class PieDemoController {  
    public Campaign camp {get;set;}
    
    public PieDemoController(ApexPages.StandardController std){
        camp = (Campaign)std.getRecord();
        
    }
    
    public List<PieWedgeData> getPieData() {
        List<PieWedgeData>PieWedgeData = new List<PieWedgeData>();
        List<AggregateResult> opps = [SELECT SUM(Amount) monthlyRevenue, COUNT(Name) numOppsClosedWon,
                  CALENDAR_MONTH(CloseDate) theMonth
             FROM Opportunity
             WHERE CampaignId =: camp.id 
             GROUP BY CALENDAR_MONTH(CloseDate)];
        
        for(AggregateResult ar : opps){
            String month = String.valueOf(ar.get('theMonth')); //this comes out as a number, not a word value
            Integer revenue = Integer.valueOf(ar.get('monthlyRevenue'));
           PieWedgeData.add(new PieWedgeData(month, revenue));
        }
        return PieWedgeData;
    }
    
    public class PieWedgeData {
       
        public PieWedgeData(String name, Integer count) {
            this.name = name;
            this.count = count;
        }
         public String name { get; set; }
        public Integer count { get; set; }

    }
}

Thanks in advance
Hi, need your help for this error
Illegal assignment from List<SObject> to List<ProcessInstance> (46:31)
public with sharing class ProcessInstance {
    @AuraEnabled(cacheable=true)
    public static List<ProcessInstance> getCases(
        String relatedTo,
        String submittedDate,
        String submittedBy
    ) {
        String query;
        String condition = (String.isNotBlank(relatedTo)
            ? 'TargetObject.name LIKE \'' + '%' + relatedTo + '%\''
            : '');

        condition += (String.isNotBlank(submittedDate)
            ? (String.isNotBlank(condition) ? +' AND ' : '') +
              ' LastModifiedDate LIKE \'' +
              '%' +
              submittedDate +
              '%\''
            : '');

        condition += (String.isNotBlank(submittedBy)
            ? (String.isNotBlank(condition) ? +' AND ' : '') +
              ' SubmittedBy.name LIKE \'' +
              '%' +
              submittedBy +
              '%\''
            : '');

        System.debug('condition ' + condition);
        if (String.isNotBlank(condition)) {
            query =
                'SELECT TargetObject.name,LastModifiedDate,SubmittedBy.name FROM ProcessInstance WHERE ' +
                condition +
                ' ORDER BY LastModifiedDate';
        } else {
            query = 'SELECT TargetObject.name,LastModifiedDate,SubmittedBy.name FROM ProcessInstance ORDER BY LastModifiedDate LIMIT 200';
        }

        List<ProcessInstance> records = Database.query(query);
        return records;
    }
}

 

Hello!

I'm having trouble creating this formula for a validation rule. This is what I'm trying to accomplish, If the Engagement plan template's default assignee is blank, then I would like for the contact's "pathway coach" to be assigned. No errors were found, but the engagement plan tasks are assigned to me (the contact owner) despite the default assignee being blank

AND(ISPICKVAL( npsp__Engagement_Plan_Template__r.npsp__Default_Assignee__c ,
"--None--"),
ISNULL( npsp__Assigned_To__r.Contact.Pathway_Coach__c ))

My Requirement:
 I have one custom profile (Test User)  and  one Custom Object.
 This profile having delete access on Opportunity,Contact and this Custom Object.
 Now I want to write a trigger to restrict user with ""Test User"" profile from deleting above mentioned   3 object records.

Or a sinlge apex class that will work on these 3 objects.

Thank you in advance
Salesforce Flow: Populate "primary contact" on opportunity at lead conversion using before trigger ?
Primary_Contact is Custom field
----------------------------------------------------------------------------------------------
Please Do it in Flows
@RestResource(URLMapping = '/OpportunityService/*')
global class OpportunityRecord 
{
    @HttpGet()
    global static list<Opportunity> GetOpportunityRelated ()
    {
        
      Map<string, string> inputParams = RestContext.request.Params;
        
        list<Opportunity> lstOpportunity = [select id,name, amount, stagename, closedate, accountId, Account.Name
                                             from Opportunity where Account.Name =: inputParams.Get('accName')];
        
        return lstOpportunity;
        
    }
}
Hi,
Can anyone please help me convert the below to JSON:

@AuraEnabled
  public static List<Energy_Plan__c> getRatePlans(
    String brand,
    String priceBook,
    String commodity,
    String utility,
    Boolean showPoints
  ) {
    System.debug('Inside getRatePlans');
      List<Energy_Plan__c> String query =
      'SELECT Id, Name, TermInMonths__c, REP_Per_Usage_Charge1__c, MonthlyFee__c, jurisdiction__c, ProductName__c, ' +
      'EFL_ENGLISH_LINK__c, EFL_SPANISH_LINK__c, PenaltyAmount__c, PlanType__c, Price_Units__c, Rateplan_Points__c,  ' +
      'Monthly_Fee_Total__c, ReportGroupID__c, Commodity__c, Brand__c, EnergyProvide__c,Active__c, UtilityName__c, Total_Fee__c, REPKey1__c, ExternalId__c, ' +
      'TOSLINKSTATIC_English__c, TOSLINKSTATIC_Spanish__c,External_Plan_Key__c ' +
      'FROM Energy_Plan__c ' +
      'WHERE ' +
      'Active__c = true ' +
      'AND IsCustomPriced__c = False ' +
      'AND Brand__c = :brand ' +
      'AND RateName__c = :priceBook ' +
      'AND Commodity__c = :commodity ' +
      'AND UtilityName__c = :utility ';

    if (showPoints) {
      query += 'ORDER BY Rateplan_Points__c DESC';
    } else {
      query += 'ORDER BY Name';
    }

    System.debug('getRatePlans >> ' + Database.query(query));

    return Database.query(query);

I have an aura component that is sitting on a grey background, so I need the field labels of my lightning:input boxes to have white text. But the text boxes themselves are white, so I need the text entry within the boxes to stay default black. No,  I cannot change the background on this page due to branding, etc.

 

Every solution I've tried so far has changed the text entry in the boxes to white while leaving the labels black, which is the exact opposite of what I need. Any ideas? Thank you!

Hello, trying to compose a SOQL that will retrieve recently Closed Won Opportunities unless the Opportunity has only 1 of 2 specific Products. Here is my last attempt:

SELECT Id, CloseDate, Name, Owner.Name, Account.Name FROM Opportunity WHERE StageName = 'Closed Won' AND CloseDate = LAST_N_DAYS:30 AND Id NOT IN (SELECT Opportunity.Id FROM OpportunityLineItem WHERE Opportunity.StageName = 'Closed Won' AND Opportunity.CloseDate = LAST_N_DAYS:30 AND Opportunity.CountofProducts__c = 1 AND PricebookEntry.Product2.Name NOT IN ('Product Name 1', 'Product Name 2') )

FYI, I've tried to qualify the sub-select as much as possible to avoid limit errors, and Opportunity.CountofProducts__c is a basic custom Rollup Summary COUNT of Opportunity Products.

I am encountering this error:
MALFORMED_QUERY:
LAST_N_DAYS:30 AND Id NOT IN (SELECT Opportunity.Id FROM OpportunityLineItem
^ (points to the space between SELECT and Opportunity)
ERROR at Row:1:Column:155
The inner select field 'Opportunity.Id' cannot have more than one level of relationships

Any suggestions for how to re-write?
 
Hello Experts,

We have various Process Builder, Workflow rules and Flow. 

We are unable to check how a specific CASE is created and certain fields are updated automitally.

What and which way we can find out how this CASE was generated?

Any help would be great.

Thank you
Is there a way for me to test out a Web-To-Lead form? I'm just creating this is in a Dev Org. I've created a Round Robin Lead Assigment so Web leads will be distributed out fairly. How can I best test this out to make sure to works? Thanks!

Hi!

I need to add gift cards to an opportunity if the checkbox is enabled, otherwise it will throw an error. In this case, the entered card is deactivated. In the future, I don't have the ability to change any of the opportunity field as the validation fires. How can I solve this problem?
public class OpportunityTriggerHandler {
    
         public void afterInsert (List<Opportunity> newOpportunities){
            List<String> cardNames = new List<String>();
            for(Opportunity oppItem : newOpportunities) {
                cardNames.add(oppItem.Gift_Card__c);
            }
            List<Gift_Card__c> giftCardToUpdate = [SELECT Active__c, Amount__c, Name 
                                                  FROM Gift_Card__c 
                                                  WHERE Name IN :cardNames];    
           
            for(Gift_Card__c giftCard: giftCardToUpdate ) {
                giftCard.Active__c = false;
            }
            
            update giftCardToUpdate;
        } 
        
         
        public void beforeInsert (List<Opportunity> newOpportunities){
            List<String> cardNames = new List<String>();
            for(Opportunity oppItem : newOpportunities) {
                cardNames.add(oppItem.Gift_Card__c);
        }
            List<Gift_Card__c> allGiftCards = [SELECT Active__c, Amount__c, Name 
                                           FROM Gift_Card__c 
                                           WHERE Name IN :cardNames];
            for (Opportunity newOpp: newOpportunities) {
                for(Gift_Card__c giftCard: allGiftCards ) { 
                        if (giftCard.Active__c == true) {
                        newOpp.Amount -= giftCard.Amount__c;
                     } else {
                     newOpp.Gift_Card__c.addError('Gift Card is inactive');
                         }
                    }
                }  
            }
        }