• Prince_sfdc
  • NEWBIE
  • 100 Points
  • Member since 2015

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 25
    Replies
I am trying to build a query to help with buyer-journey reporting. I am trying to do this with only SOQL, not Apex. I think I might be querying the wrong object but I'm not sure how to build this query to give me everything I need.

Here is my query: 

SELECT Id,FirstRespondedDate,Campaign.Name,Status,Date_Responded__c,CreatedDate,ContactId FROM CampaignMember WHERE CampaignId IN (SELECT CampaignId FROM Opportunity WHERE StageName = 'Closed–Won' AND CloseDate = THIS_YEAR) AND ContactId IN (SELECT ContactId FROM OpportunityContactRole)

This works and gives me almost everything I need, but I need to return CloseDate in addition to these other fields. Is this possible? Do I need to flip this and query the Contact object instead, using nested queries to grab both campaign member and opportunity fields?
what is the difference between the getValue() and getLabel() in PickListEntry Class, please explain with an example for each.
Initial term of field expression 
​must be a concrete SObject: List<Contact> at line 12 column 6.
 
trigger CreateContact on Account (After Insert)
{
 
 //Collection of contacts for saving new contacts.
 List<Contact> conList =new List<Contact>();
 
 for(Account acc: trigger.new)
 {
     // For each Account create a new Contact.
     List<Contact> freshCon=new List<Contact>();
     
     freshcon.Accountid=acc.id;
     freshcon.LastName=acc.Name +'_'+ acc.CustomerPriority__c;
     
     //add new Contact to the collection.
     conList.add(freshcon);
     
 }
 
insert conList;
 

}
An error is getting encountered "Collection size 1,738 exceeds maximum size of 1,000" , when I click on a installed package's app. 

I've a app exchange product installed in my or i.e. Easy Describe, but when I go to my list of my apps and click easy describe it throws this error. 
I'm perplexed how to resolve. 
when I run the block of ‘static’ code in execute anonymous, it throws an error “only top-level methods in the class are allowed to be declared as static”. I tried my code also: there also same issue.
 public StringArrayTest {  public static void generateStringArray() {}  }
 Can anyone help on this?

thank you.
  global void execute(Database.BatchableContext BC, list<case> caseList){
        set<Id> getIDs = new Set<Id>();
        Map<Id,Id> caseWithCasePlanIdMap = new Map<Id,Id>();
        Map<Id, List<String>> casePlanWithGoalsMap = new Map<Id, List<String>>();
       
        for(Case cse : caseList){
            if(cse.Case_Plans__r != null && cse.Case_Plans__r.size() >0){
                caseWithCasePlanIdMap.put(cse.id, cse.Case_Plans__r[0].Id);
            }
        }
        system.debug('caseWithCasePlanIdMap'+caseWithCasePlanIdMap);
        Map<Id, case> caseMap = new Map<Id, case>(caseList);
        System.debug('caseMap'+caseMap);
        for(caseman__Goal__c goal : [SELECT Id,Name, caseman__CasePlan__c, caseman__Status__c FROM caseman__Goal__c 
                                     where caseman__CasePlan__c IN: caseWithCasePlanIdMap.values() AND caseman__Status__c !='Completed']){ // 'a0SM000000EBStkMAH' ]){
                                         System.debug('caseWithCasePlanIdMap.values()'+caseWithCasePlanIdMap.values());
                                         System.debug('goal'+goal);
                                         if(!casePlanWithGoalsMap.containskey(goal.caseman__CasePlan__c)){
                                             casePlanWithGoalsMap.put(goal.caseman__CasePlan__c, new List<String>());
                                         }
                                         casePlanWithGoalsMap.get(goal.caseman__CasePlan__c).add(goal.Name);
                                         casePlanWithGoalsMap.get(goal.caseman__CasePlan__c).add(goal.caseman__Status__c);
                                     }
        System.debug('casePlanWithGoalsMap'+casePlanWithGoalsMap);
        
        CaseSevenDayFollowUpEmailBatch.afterSevenDaysEmail(caseList,casePlanWithGoalsMap);

 global static void afterSevenDaysEmail(List<case> CaseList,  Map<Id, List<String>> casePlanData){
        System.debug('casePlanData'+casePlanData);
        // for(case cas : CaseList){
        //  for(caseman__CasePlan__c  c : cas.Case_Plans__r){
        // for(caseman__Goal__c  go :c.caseman__Goals__r){
        // List<caseman__CasePlan__c> casePlanList =[Select id, Name, caseman__Status__c From caseman__CasePlan__c WHERE caseman__Status__c!= 'Completed'];
        Integer casePlanLength= casePlanData.size();
        
        System.debug('casePlanLength'+casePlanLength);
        // }
        //}         
        // } 
        if(casePlanData.size() > 0){ //casePlanLength
            system.debug('casePlanData.size()'+casePlanData.size());
            //  Set<Id> casePlanId = new Set<Id>();
            
            
            Set<id> goalIdSet = new Set<Id>();
            for(case ca :CaseList){
                for(caseman__CasePlan__c casePlan1 : ca.Case_Plans__r){
                    System.debug('caseman__Goals__r'+casePlan1.caseman__Goals__r);
                    for(caseman__Goal__c goal : casePlan1.caseman__Goals__r){
                        
                        System.debug('goal - ' + goal);
                        goalIdSet.add(goal.Id);
                    }
                    
                    Map<id,List<caseman__ActionItem__c>> actionItemMap = new Map<id,List<caseman__ActionItem__c>>();
                    List<caseman__ActionItem__c> actionItemList = [Select Id,Name,caseman__Goal__c,caseman__Status__c
                                                                   from caseman__ActionItem__c where caseman__Goal__c =: goalIdSet];
                    System.debug('actionItemList'+actionItemList);
                    for(caseman__ActionItem__c item : actionItemList){
                        if(actionItemMap.containsKey(item.caseman__Goal__c))
                        {   
                            actionItemMap.get(item.caseman__Goal__c).add(item);
                            
                        }
                        else 
                        {   
                            actionItemMap.put(item.caseman__Goal__c,new list<caseman__ActionItem__c>{item}); 
                        }
                    }        
                    String casePlanStatus = '';
                        String caseGoalStatus = '';
                        if(iterCase.Case_Plans__r.size() > 0) {
                            casePlanStatus = '<br/>'+iterCase.Case_Plans__r[0].caseman__Status__c+'<br/>';
                            System.debug('casePlanStatus'+casePlanStatus);
                            System.debug('casePlanData - ' + casePlanData);
                            if(casePlanData.size() > 0){
                              //  System.debug('casePlanData - ' + casePlanData.get('caseman__Status__c'));
                                  caseGoalStatus = '<br/>'+casePlanData[1]+'<br/>';
                                System.debug('caseman__Goal__c.caseman__Status__c'+caseman__Goal__c.caseman__Status__c);
                                 System.debug('caseGoalStatus'+caseGoalStatus);
                            }
                        }
}
}



 
System.NullPointerException: Attempt to de-reference a null object
Class.OpportunityUpdateFromTicketHandler.emailNotificationFromIteroBackOffice: line 30, column 1
Class.OpportunityUpdateFromTicketHandlerTest.emailNotificationFromIteroBackOfficeTest: line 76, column 1

Apex class :
-----------------
ublic class OpportunityUpdateFromTicketHandler {
    
    Public static void sendEmail(List<String> toAddress,EmailTemplate et)
    {
       List<Messaging.SingleEmailMessage> allmsg = new List<Messaging.SingleEmailMessage>();
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                mail.setTemplateId(et.Id);
                mail.setToAddresses(toAddress);
                mail.setSubject(et.subject);
                mail.setHTMLBody(et.Body);
                allmsg.add(mail);
            Messaging.sendEmail(allmsg);
        
    }
    Public static EmailTemplate getQuery(String tempname)
    {
      EmailTemplate et = [select id,Subject,Body from EmailTemplate where DeveloperName =: tempname];
        return et; 
    }
    // created by Jayaramu for Technical Det story
    Public static void emailNotificationFromIteroBackOffice(List<case> ticketList,Map<Id,Case> oldMapCase)
    {
        EmailTemplate et = getQuery('iTero_back_office_Template');
        system.debug('@@@@@@@@@'+et);
        Map<ID, RecordType> recordTypeMap = New Map<ID, RecordType>([Select ID, Name From RecordType Where sObjectType = 'Case']);
        List<string> toAddress = new List<string>();    
        for(Case ticket :ticketList)
        {
        if(recordTypeMap!=null && ticket !=null && recordTypeMap.get(ticket.recordTypeID).name.containsIgnoreCase('iTero Contracts') && ticket.Ticket_Type__c =='New scanner sale' && ticket.Final_Status__c != oldMapCase.get(ticket.Id).Final_Status__c && ticket.Final_Status__c =='Processed/Assigned to Logistics' )
        {
            if(ticket.Region__c =='NA' || ticket.Region__c =='LATAM')
            {
              toAddress.add('test@gmail.com');
                system.debug('#######' + ticket.managerid__c);
                if(toAddress !=null && et!=null)
                {
                    sendEmail(toAddress, et);
                }
                
            }
        }
        
        }
   }

Test Class
------------------
@isTest
public class OpportunityUpdateFromTicketHandlerTest {
        public static Id eUiteroRecordTypeId  =  Schema.SObjectType.Case.getRecordTypeInfosByName().get('iTero Contracts').getRecordTypeId();
    public static Id eUiteroRecordTypeId1  =  Schema.SObjectType.Case.getRecordTypeInfosByName().get('Incentive Compensation Request').getRecordTypeId();
    //public static Id eUiteroRecordTypeId2  =  Schema.SObjectType.Case.getRecordTypeInfosByName().get('iTero Training').getRecordTypeId();
  @isTest static void emailNotificationFromIteroBackOfficeTest(){
      Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator']; 
      Userrole objr = [SELECT Id FROM UserRole WHERE Name = 'Global Administrator' LIMIT 1];
       User thisUser = new User(Alias = 'standt', Email='contractdesk@testorg.com', 
                                 EmailEncodingKey='UTF-8', LastName='contractdesk', LanguageLocaleKey='en_US', 
                                 LocaleSidKey='en_US', ProfileId = p.Id,UserRoleId = objr.Id,
                                 TimeZoneSidKey='America/Los_Angeles', UserName='contractdesk@testorg.com');
        TestDataBuilder testBuilder = new TestDataBuilder();
        //insert manager
        User usrManager             = new User();
        usrManager          = testBuilder.dummyUser(0);
        usrManager.UserRoleId = objr.Id;
        insert usrManager; 
        //Insert User
        User usr                = new User();
        usr             = testBuilder.dummyUser(1);
        usr.ManagerId   = usrManager.Id;
        usr.UserRoleId = objr.Id;
        
        insert usr;
      
      System.runAs(thisUser){
      List<case> caseList = new List<case>();
        //insert Case
        Case cse                    = new Case();
        cse.RecordTypeId    = eUiteroRecordTypeId;
        cse.Ticket_Type__c  = 'New scanner sale';
        cse.Origin          = 'Web';
        cse.Final_Status__c ='Processed/Assigned to Logistics';
        cse.Region__c = 'NA';
        //cse.Status='Approved';
        cse.Type_of_Credit__c='Internal';
        cse.Reason_for_Credit__c='Staff Discount Coupon';
        cse.Subject='Testing';
        cse.Invoice_Number__c='1234567891';
        cse.Amount_of_credit__c=10;
        cse.Order_type__c='webstore';
        cse.Sales_Order_Number__c='123456';
      caseList.add(cse);
      Case cse1                    = new Case();
        cse1.RecordTypeId    = eUiteroRecordTypeId;
        cse1.Ticket_Type__c  = 'New scanner sale';
        cse1.Origin          = 'Web';
        cse1.Final_Status__c ='Processed/Assigned to Logistics';
        cse1.Region__c = 'NA';
        //cse1.Status='Approved';
        cse1.Type_of_Credit__c='Internal';
        cse1.Reason_for_Credit__c='Staff Discount Coupon';
             cse1.Subject='Testing';
        cse1.Invoice_Number__c='1234567891';
        cse1.Amount_of_credit__c=10;
        cse1.Order_type__c='webstore';
        cse1.Sales_Order_Number__c='123456';
         caseList.add(cse1);
          EmailTemplate et = OpportunityUpdateFromTicketHandler.getQuery('iTero_back_office_Template');
            emailmessage em = new emailmessage();
                em.fromaddress = 'Test@test.com';
                em.toaddress = 'test1@test.com';
                em.subject = 'Test Email';
                em.textbody = 'testing';
                em.parentid = caseList[0].id;
                test.starttest();
                insert em;
      Map<Id,Case> oldMapCase = new Map<Id,Case>(); 
      insert caseList;
      oldMapCase.put(cse.Id, cse);
       System.assertEquals(0, Limits.getEmailInvocations(), 'No emails should be sent');

       OpportunityUpdateFromTicketHandler.emailNotificationFromIteroBackOffice(caseList,oldMapCase);

       System.assertEquals(1, Limits.getEmailInvocations(), 'Emails should be sent');
       Test.stopTest();
      }
  }
        
  }


Thanks!!
  • September 08, 2022
  • Like
  • 0
I am trying to cover a method which uses formula field.
This is my test class code:

SObject1__C coltype = new SObject1__C();
coltype.name = 'Name-3312';
insert coltype;
System.debug('--->SObject1.Name = '+coltype.name); // Gives 'Name-3312';

SObject2__C colObj = new SObject2__C();
colObj.SObject1__C = coltype.Id;
insert colObj;  

SObject3__C newCollP = new SObject3__C();
newCollP.SObject2__C = colObj.Id,
insert newCollP;

SObject3__C has a fomula field named 'Col_Type__C' which is evaluated as follows:
"SObject2__r.SObject1__r.Name"
System.debug('--->newCollP.Col_Type__C = '+ newCollP.Col_Type__C); //returns a2Hg0000001tqQ2

This 'Col_Type__C' field's value is then used in a method in a helper class which i am trying to cover. As posted by many, I have tried to query the object SObject3__C and populate the field Col_Type__C in the test class as below. But it's not populatting the formula field's value as 'Name-3312'. 
newCollP = [SELECT Id,SObject2__r.SObject1__r.Name, Col_Type__C from SObject3__C where Id=:newCollP.id];

When I debug Col_Type__C value in helper class it returns some ID. I need the value of  as name of SObject1__C.

What is missing in my code? How can I get the formula field populated? 

Any help is appreciated!
I am trying to build a query to help with buyer-journey reporting. I am trying to do this with only SOQL, not Apex. I think I might be querying the wrong object but I'm not sure how to build this query to give me everything I need.

Here is my query: 

SELECT Id,FirstRespondedDate,Campaign.Name,Status,Date_Responded__c,CreatedDate,ContactId FROM CampaignMember WHERE CampaignId IN (SELECT CampaignId FROM Opportunity WHERE StageName = 'Closed–Won' AND CloseDate = THIS_YEAR) AND ContactId IN (SELECT ContactId FROM OpportunityContactRole)

This works and gives me almost everything I need, but I need to return CloseDate in addition to these other fields. Is this possible? Do I need to flip this and query the Contact object instead, using nested queries to grab both campaign member and opportunity fields?
Hi,

While going through the code of one of the class in my project I found that PriceBookEntry object is used. However when I tried to find it in setup/object menu I couldn't find. But I can find this object in eclipse as PricebookEntry.object.

Can anyone please let me know how I can find it in setup.

Arun.
what is the difference between the getValue() and getLabel() in PickListEntry Class, please explain with an example for each.
Hi,

I have executed "Run all test" to get code coverage of all apex classes. Is there way to get all apex classes code coverage with percentage copy to excel sheet. I am able to see all classes with percentage in Developer console. But not able to copy all those. Please provide some suggestion.
Hi,

Problem with "Creating Global Quick Actions" Module

There was an unhandled exception. Please reference ID: TGHDVSER. Error: Faraday::Error::ResourceNotFound. Message: NOT_FOUND: The requested resource does not exist

I've tried this several times now, over two days.  Deleted and recreated, but still get the same error.

Would really like to complete this module.  Any help appreciated.  thanks, 
Is there something special that I have to do to have ProcessBuilder findmy email templates?
Hi All,

We have created Communities and have configured for a group of users. Now we have around 2000+ community users who will be accessing the community. We know that we have to create them as Contact and 'Enable as Customer User' manually. But for this amount of users, the time is main factor.
  • Is there a way we can Mass enable contacts as Community Users?
  • If not, Is there any other woraround or Any App that creates Mass Community users?
  • If we use Data Loader, can we import users with Customer Community license and Roles?
Any help would be highly appreciated. Thanks a lot in advance!

Regards,
Raghu

I'm trying to send an email that includes a link to a record in Saleforce using apex email alert and the setHtmlBody method.  I'm trying to send the link like so..

 

<a href="'+URL.getSalesforceBaseUrl()+'/'+workOrder.id+'">'+workOrder.Name+'</a>

 The email gets sent out just fine, but the link isn't there.  When I look at the source in the email it shows the a tag without the href attribute like so...

<a>Work Order Name</a>

 Can anybody tell me why this is happening and what I can do to get the link to work?

  • December 04, 2013
  • Like
  • 0

Hi ,

 

Could someone please point out the difference between 'save to database' and 'Commit to database'? This will be really helpful.

 

Thanks

Sam

I am trying to show and hide <div> when a drop down from a list from a custom field.

 

For example, if I have a dropdown value of

1) value 1

2) value 2

3) value 3

 

When I select value 3, it will show a hidden <div> with jQuery in visualforce page.

 

I can do this in the standard html page, using ids and classes—but I don't know how to put id's or classes' on value 3 because it is a custome field from salesforce...

Hi,

 

In lookups for standard object, we have New button on lookup dialig.

Is it possible to have New button on lookup dialog for Cutom Object. If yes please let me know the steps or workaround

 

Thanks

trigger FindMarketTerritoryFromMarket on Territory_Market__c (before insert, before update) { Map<Id,Territory_Market__c> territoryMarket= new Map<Id,Territory_Market__c>(); for(Territory_Market__c t : Trigger.new) { if(t.Parent_Market__c!=Trigger.oldMap.get(t.Id).Parent_Market__c){ territoryMarket.put(t.Id,t); System.debug(t.Parent_Market__c); } } List<Account> updateAccount = new List<Account>(); Map<Id,String> setAccount= new Map<Id,String>(); for(Id ids : territoryMarket.KeySet()){ List<Account> account = new List<Account>(); account = [Select a.Name From Account a limit 1]; } }

 

this is my code. I removed update account code from this.

 

This is simple code not doing anything yet,still it fails at account = [Select a.Name From Account a limit 1]; line.

 

It giveme error :

 

Review all error messages below to correct your data.
Apex trigger FindMarketTerritoryFromMarket caused an unexpected exception, contact your administrator: FindMarketTerritoryFromMarket: execution of BeforeUpdate caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times): Trigger.FindMarketTerritoryFromMarket: line 31, column 8

 

I tried to pass only not null value still same problem. Then I rmoved all where condition and trying very simple query,still didn't help.

 

Can someone let me know workaroud for this problem?

 

Thanks