• Bryan Leaman
  • NEWBIE
  • 30 Points
  • Member since 2014

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 11
    Replies
Hello,

I'm getting the following data :
SELECT 
  Id,
  Contact.Id,
  Contact.Name,
  Contact.AccountId,
  Contact.Account.Name 
FROM CampaignMember
WHERE Campaign.Type = 'Programme Application'
Now for each row I would like the count of each contact in the account with a CampaignMember.
SELECT 
  COUNT()  
FROM CampaignMember
WHERE Contact.AccountId = $$CURRENT_CONTACT_ACCOUNT$$
I tried the following but it doesn't works :
SELECT 
  Id,
  Contact.Id,
  Contact.Name,
  Contact.AccountId,
  Contact.Account.Name,
  (SELECT 
       COUNT()  
   FROM CampaignMember cm2
   WHERE cm2.Contact.AccountId = cm.Contact.AccountId) as countMDC  
FROM CampaignMember cm
WHERE Campaign.Type = 'Programme Application'
With APEX i tried to parse every row of the first query to run the second query, but i can't access the Contact.AccountId value of each row. The returned object is a CampaignMember with only ContacId, CampaignMemberID and CampaignId.
for(SObject currentContact : [SELECT 
	                          Id,
							  Contact.Id,
							  Contact.Name,
							  Contact.AccountId,
							  Contact.Account.Name 
							  FROM CampaignMember
							  WHERE Campaign.Type = 'Programme Application']){
			System.debug(currentContact);
}
The foreach result
Have you any idea how to do it ? It looks very simple problem but i'm stuck since few hours now ... oO'
IF(
AND(  ISPICKVAL( Country1__c  , 'US')),   
  (ISPICKVAL( STATE1__c   , 'CA')),  "WEST",
IF( 
AND(ISPICKVAL(Country1__c  , 'US'),  (ISPICKVAL( STATE1__c, 'OL')), "EAST",
"OTHERS")))

 Error: Incorrect parameter type for function 'AND()'. Expected Boolean, received Text

Hi All, 
Here  i trying to write a trigger  when opportunity stage will Closed won...one custom field name Opportunity_Checkedbox__c in account should active. 

it's showing error 

In Line 12 - Comparison arguments must be compatible types: Boolean, String

.....Trigger.....

trigger OpportunityAccTrigger on Opportunity (after Update) {
    
    if(Trigger.isAfter && Trigger.isUpdate){
        OpportunityAccTriggerHandler.afterUpdate(Trigger.new, Trigger.OldMap);
    }

}

...........Trigger Handler......for after update

public class OpportunityAccTriggerHandler {
    
   
    public static Void afterUpdate(List<Opportunity> newList, Map<Id,Opportunity> OldMap){
        set<ID> ids = new Set<ID> ();
        Map<Id,Boolean> OppToBeMapped = new Map<Id,Boolean>();
        List<Opportunity> OppList = new List<Opportunity>();
        List<Account> accList = new List<Account>();
        
        for(Opportunity Opp: newList){

            if(OldMap!=null && Opp.StageName =='Clossed Won'!= oldMap.get(Opp.Id).StageName =='Closed Won'){   
            }
        }
         
        for(Account Acctt : [SELECT Id, Opportunity_Checkedbox__c  FROM Account Where Id In :ids]){
            
            Account acc = new Account();
            if(OppToBeMapped.Containskey(acc.id)){
                Acctt.Opportunity_Checkedbox__c = true;
                accList.add(Acctt);
            
            }
            if(accList.size()>0)
            update accList;
        }
            
   }
}

I have a requirement to split the string based on delimeter, compare the tokens with specific value and if it finds a match, clear that specific value or replace it with other value .
Example 1 : string 'test,krishna,shekhar, karjun' need to be split based on comma (,) and compare each value with word 'shekhar', since match is found clear the word shekhar from original string . So the updated string value will be ''test,krishna,karjun' ( Shekhar is removed including delimeter )
Can you plesae suggest the best way to achieve this rquirement ?
Getting the above error while running the apex class with wrapper class


public class getComments {
    public static void getTickets(){
        HTTP h = new HTTP();
        HTTPRequest r = new HTTPRequest();
        //setHeader('Content-Type', 'application/json');
        r.setHeader('Accept','application/json');
        
        r.setEndpoint('https://criticalriver3509.zendesk.com/api/v2/tickets/2/comments');
        string userName='yatendra.kumar@criticalriver.com';
        string password='yuvi@2552';
        Blob headerValue = Blob.valueOf(username + ':' + password);
        String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
        r.setHeader('Authorization', authorizationHeader);
        r.setMethod('GET');
        HTTPResponse resp = h.send(r);
        system.debug(resp.getBody());
       parseZenJSON allTickets = (parseZenJSON)JSON.deserialize(resp.getBody(), parseZenJSON.class);
        system.debug('allTickets---->>'+allTickets);
        //list<case> allCase = new list<case>();
      // for(fromJson.comments t:allTickets.comments)
       // {
       //    
   //    }
    
    
    }  
Can anyone help me why I have this error: Too many soql queries inside my code?
 
for(SVMXC__SVMX_Event__c svEv: listSvmxEvents )  
            {
            
                String key = '' + svEv.SVMXC__Technician__r.SVMXC__Salesforce_User__c + svEv.SVMXC__StartDateTime__c.date();  
                SVMXC__Timesheet_Day_Entry__c tde = dayEntries.get(key);
            
                Map<ID, ID> technicianTImesheet = new Map<Id,ID>();
                technicianTImesheet.put(svEv.Id, svEv.SVMXC__Technician__r.SVMXC__Salesforce_User__c);
                
          //if there are no timesheet daily summary create them -> Start
                
                if(tde == null)
                {
                    List<SVMXC__Timesheet__c> latestTimesheet = [SELECT Id,SVMXC__User__c,Name,SVMXC__Start_Date__c, Day_of_the_week__c FROM SVMXC__Timesheet__c WHERE SVMXC__User__c =: technicianTImesheet.values() ORDER BY SVMXC__Start_Date__c DESC LIMIT 1]; 
                    String technicianSalesforceId = svEv.SVMXC__Technician__r.SVMXC__Salesforce_User__c;
                    Date dateServiceMaxEvent =      svEv.SVMX_PS_Customer_Start_Date__c;
                    String dayOftheWeek =           svEv.Day_of_the_week__c;
                  for(SVMXC__Timesheet__c tm : latestTimesheet){ 
                    if(dayOftheWeek == 'Monday' && tm.Day_of_the_week__c == 'Monday')
                    {
                        System.debug('Monday');
                        SVMXC__Timesheet__c newTimesheet = new SVMXC__Timesheet__c();
                        newTimesheet.SVMXC__User__c = technicianSalesforceId;
                        newTimesheet.SVMXC__Start_Date__c = dateServiceMaxEvent;
                        newTimesheet.SVMXC__End_Date__c = newTimesheet.SVMXC__Start_Date__c +6;
                        List<SVMXC__Timesheet__c> existingTimesheet = [SELECT Id,SVMXC__Start_Date__c, SVMXC__End_Date__c FROM SVMXC__Timesheet__c WHERE SVMXC__Start_Date__c =: newTimesheet.SVMXC__Start_Date__c AND  SVMXC__User__c =: technicianSalesforceId]
                        
                        if(existingTimesheet.size() == 0)
                        {
                            insert newTimesheet;

                        }
                       }
                    }
                   for(SVMXC__Timesheet__c tm : latestTimesheet){
                    if(dayOftheWeek == 'Tuesday' && tm .Day_of_the_week__c == 'Monday')
                    {
                        System.debug('Tuesday ' +svEv.Id );
                        SVMXC__Timesheet__c newTimesheet = new SVMXC__Timesheet__c();
                        newTimesheet.SVMXC__User__c = technicianSalesforceId;
                        newTimesheet.SVMXC__Start_Date__c = dateServiceMaxEvent - 1;
                        System.debug('newTimesheet.SVMXC__Start_Date__c dateServiceMaxEvent - 1' + newTimesheet.SVMXC__Start_Date__c);
                        newTimesheet.SVMXC__End_Date__c = newTimesheet.SVMXC__Start_Date__c +6;
                        List<SVMXC__Timesheet__c> existingTimesheet = [SELECT Id,SVMXC__Start_Date__c, SVMXC__End_Date__c FROM SVMXC__Timesheet__c WHERE SVMXC__Start_Date__c =: newTimesheet.SVMXC__Start_Date__c AND  SVMXC__User__c =: technicianSalesforceId]; 
                        
                        if(existingTimesheet.size() == 0)
                        {
                            insert newTimesheet;

                        }
                       }
                    }
                  
                  for(SVMXC__Timesheet__c tm : latestTimesheet){
                    if(dayOftheWeek == 'Wednesday' && tm .Day_of_the_week__c == 'Monday')
                    {
                        SVMXC__Timesheet__c newTimesheet = new SVMXC__Timesheet__c();
                        newTimesheet.SVMXC__User__c = technicianSalesforceId;
                        newTimesheet.SVMXC__Start_Date__c = dateServiceMaxEvent - 2;
                        newTimesheet.SVMXC__End_Date__c = newTimesheet.SVMXC__Start_Date__c +6;
                        List<SVMXC__Timesheet__c> existingTimesheet = [SELECT Id,SVMXC__Start_Date__c, SVMXC__End_Date__c FROM SVMXC__Timesheet__c WHERE SVMXC__Start_Date__c =: newTimesheet.SVMXC__Start_Date__c AND  SVMXC__User__c =: technicianSalesforceId];
                        
                        if(existingTimesheet.size() == 0)
                        {
                            insert newTimesheet;
                          
                        }
                        }
                    }
                  
                  for(SVMXC__Timesheet__c tm : latestTimesheet){
                    if(dayOftheWeek == 'Thursday' && tm .Day_of_the_week__c == 'Monday')
                    {
                        SVMXC__Timesheet__c newTimesheet = new SVMXC__Timesheet__c();
                        newTimesheet.SVMXC__User__c = technicianSalesforceId;
                        newTimesheet.SVMXC__Start_Date__c = dateServiceMaxEvent - 3;
                        newTimesheet.SVMXC__End_Date__c = newTimesheet.SVMXC__Start_Date__c +6;
                        List<SVMXC__Timesheet__c> existingTimesheet = [SELECT Id,SVMXC__Start_Date__c, SVMXC__End_Date__c FROM SVMXC__Timesheet__c WHERE SVMXC__Start_Date__c =: newTimesheet.SVMXC__Start_Date__c AND  SVMXC__User__c =: technicianSalesforceId]; 
                        
                        if(existingTimesheet.size() == 0)
                        {
                            insert newTimesheet;

                        }
                       }
                    }
                    
                   for(SVMXC__Timesheet__c tm: latestTimesheet){
                    if(dayOftheWeek == 'Friday' && tm.Day_of_the_week__c == 'Monday')
                    {
                        SVMXC__Timesheet__c newTimesheet = new SVMXC__Timesheet__c();
                        newTimesheet.SVMXC__User__c = technicianSalesforceId;
                        newTimesheet.SVMXC__Start_Date__c = dateServiceMaxEvent - 4;
                        newTimesheet.SVMXC__End_Date__c = newTimesheet.SVMXC__Start_Date__c +6;
                        List<SVMXC__Timesheet__c> existingTimesheet = [SELECT Id,SVMXC__Start_Date__c, SVMXC__End_Date__c FROM SVMXC__Timesheet__c WHERE SVMXC__Start_Date__c =: newTimesheet.SVMXC__Start_Date__c AND  SVMXC__User__c =: technicianSalesforceId] 
                        
                        if(existingTimesheet.size() == 0)
                        {
                            insert newTimesheet;
   
                        }
                        }
                    }
                    
                  for(SVMXC__Timesheet__c tm : latestTimesheet){
                    if(dayOftheWeek == 'Saturday' && tm .Day_of_the_week__c == 'Monday')
                    {
                        SVMXC__Timesheet__c newTimesheet = new SVMXC__Timesheet__c();
                        newTimesheet.SVMXC__User__c = technicianSalesforceId;
                        newTimesheet.SVMXC__Start_Date__c = dateServiceMaxEvent - 5;
                        newTimesheet.SVMXC__End_Date__c = newTimesheet.SVMXC__Start_Date__c +6;
                        List<SVMXC__Timesheet__c> existingTimesheet = [SELECT Id,SVMXC__Start_Date__c, SVMXC__End_Date__c FROM SVMXC__Timesheet__c WHERE SVMXC__Start_Date__c =: newTimesheet.SVMXC__Start_Date__c AND  SVMXC__User__c =: technicianSalesforceId]   
                        
                        if(existingTimesheet.size() == 0)
                        {
                            insert newTimesheet;

                        }
                       }
                    }
                  
                  for(SVMXC__Timesheet__c tm : latestTimesheet){
                    if(dayOftheWeek == 'Sunday' && tm.Day_of_the_week__c == 'Monday')
                    {
                        SVMXC__Timesheet__c newTimesheet = new SVMXC__Timesheet__c();
                        newTimesheet.SVMXC__User__c = technicianSalesforceId;
                        newTimesheet.SVMXC__Start_Date__c = dateServiceMaxEvent - 6;
                        newTimesheet.SVMXC__End_Date__c = newTimesheet.SVMXC__Start_Date__c +6;
                        List<SVMXC__Timesheet__c> existingTimesheet = [SELECT Id,SVMXC__Start_Date__c, SVMXC__End_Date__c FROM SVMXC__Timesheet__c WHERE SVMXC__Start_Date__c =: newTimesheet.SVMXC__Start_Date__c AND  SVMXC__User__c =: technicianSalesforceId];    
                        
                        if(existingTimesheet.size() == 0)
                        {
                            insert newTimesheet;
 
                        }
                        }
                      }
                    }


The error code is happening here:

 

List<SVMXC__Timesheet__c> existingTimesheet = [SELECT Id,SVMXC__Start_Date__c, SVMXC__End_Date__c FROM SVMXC__Timesheet__c WHERE SVMXC__Start_Date__c =: newTimesheet.SVMXC__Start_Date__c AND  SVMXC__User__c =: technicianSalesforceId];

​​​​​​​
Hi Team,

Can someone help me with apex class script to delete 'Named Credentials' please.

thx
Asha
Hello,

I'm getting the following data :
SELECT 
  Id,
  Contact.Id,
  Contact.Name,
  Contact.AccountId,
  Contact.Account.Name 
FROM CampaignMember
WHERE Campaign.Type = 'Programme Application'
Now for each row I would like the count of each contact in the account with a CampaignMember.
SELECT 
  COUNT()  
FROM CampaignMember
WHERE Contact.AccountId = $$CURRENT_CONTACT_ACCOUNT$$
I tried the following but it doesn't works :
SELECT 
  Id,
  Contact.Id,
  Contact.Name,
  Contact.AccountId,
  Contact.Account.Name,
  (SELECT 
       COUNT()  
   FROM CampaignMember cm2
   WHERE cm2.Contact.AccountId = cm.Contact.AccountId) as countMDC  
FROM CampaignMember cm
WHERE Campaign.Type = 'Programme Application'
With APEX i tried to parse every row of the first query to run the second query, but i can't access the Contact.AccountId value of each row. The returned object is a CampaignMember with only ContacId, CampaignMemberID and CampaignId.
for(SObject currentContact : [SELECT 
	                          Id,
							  Contact.Id,
							  Contact.Name,
							  Contact.AccountId,
							  Contact.Account.Name 
							  FROM CampaignMember
							  WHERE Campaign.Type = 'Programme Application']){
			System.debug(currentContact);
}
The foreach result
Have you any idea how to do it ? It looks very simple problem but i'm stuck since few hours now ... oO'
Hi All,
I have this Invocable Method to convert a Lead, but when the lead is successfully converted, an unwanted contact is created. But if a contact is not created, the lead is not converted. This is for a custom process that creates accounts previously and create the relationship with the lead, in this process we can not use the standard convert lead button.
Lead Conversion Code:

public static void updateLeadFields(List<inputParameters> request){
        
        //parse inputs and variables
        String accountId = request.get(0).accountId;
        String contactId = request.get(0).contactId;
        String opportunityId = request.get(0).opportunityId;
        String leadId = request.get(0).leadId;
        
        try{
            Database.LeadConvert leadConvert = new Database.LeadConvert();
            leadConvert.setLeadId(leadId);
            if(!String.isBlank(accountId)){
                leadConvert.setAccountId(accountId);
            }
            if(!String.isBlank(contactId)){
                leadConvert.setContactId(contactId);
            }
            if(!String.isBlank(opportunityId)){
                leadConvert.setOpportunityId(opportunityId);
            }
            LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=TRUE LIMIT 1];
            leadConvert.setConvertedStatus(convertStatus.MasterLabel);
            
            Database.LeadConvertResult lcr = Database.convertLead(leadConvert);
            
            system.debug(lcr);
            
        }catch(Exception e){
            System.debug('The following exception has occurred: ' + e.getMessage());
        }
    }
    
    public class inputParameters{
        @InvocableVariable
        public String accountId;
        @InvocableVariable
        public String contactId;
        @InvocableVariable
        public String opportunityId;
        @InvocableVariable
        public String leadId;
    }
Any idea how to solve this

Thanks in advance and regards
Rodolfo