• Raza0195
  • 5 Points
  • Member since 2019
  • Salesforce Developer
  • Cloud analogy

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 11
I have  a requirement where I would like to add contacts to campaign record when status(Custom Field) of Contact is Closed Lost. I was stuck at adding contacts to campaign. Can someone help me acheive this since I am new to salesforce..

//Batch Class

global class AddContactsToCampaignBatch implements Database.Batchable<SObject>{
    global Database.QueryLocator start(Database.BatchableContext BC) {
        return Database.getQueryLocator([SELECT Id, Name 
                                         FROM Campaign 
                                         WHERE Name = 'Pipeline Campaign']);
    global void execute(Database.BatchableContext BC, List<Contact> conList) {
        for(Contact con : [SELECT Id, Status__c 
                           FROM Contact]) {
                               if(con.Status__c == 'Closed Lost') {
        update conList;
    global void finish(Database.BatchableContext BC) {

Thanks in Advane....
What I have:
An accountId: '001R0000005Xk58IAC'

What I want to get:
1. Events based on the accountId.
Query I have: 
SELECT id FROM Event where AccountId = '001R0000005Xk58IAC'

2. EmailMessage based on the accountId (it's called relatedToId in emailMessage object).
Query I have: 
SELECT id FROM EmailMessage where relatedToId = '001R0000005Xk58IAC'

My question is, how can I use ONE query to get both of them?
Are there something like:
SELECT (Event.id, EmailMessage.id) from (Event, EmailMessage) where event.accountId = '001R0000005Xk58IAC' AND emailmessage.id = '001R0000005Xk58IAC'

By the way, I just need to get the number of the returned results, which means I just need to know the event.count + emailMessage.count, but I want to get them in one query.


I have data like that

Xyz  4
Xyz  4
Xyz  4
Xyz  4
AB  5
AB  5
CD  6
YD  4

I want to group by and do sum only for the distinct rows and divide each with sum. for example :
            avg would
Xyz 4   
AB  5  
CD  6
YD  4
sum 19 and avg would be 
Xyz  4  4/19
Xyz  4  4/19
Xyz  4  4/19
Xyz  4  4/19
AB  5  5/19
AB  5  5/19
CD  6  6/19
YD  4  4/19

help me on this

Hi Team,
I am trying to see if we can get old values of an object in Flows as we get in trigger using trigger.oldMap. or PriorValue in Workflows.

Thanks for your help in advance
                    system.debug('TypeAmountMap1'+TypeAmountMap);   // every time I am getting records here
                    TypeAmountMap.put(Shot.type__c, TypeAmountMap.get(Shot.type__c)+Shot.Amount__c);
                    system.debug('TypeAmountMap2'+TypeAmountMap);     // records are not getting created any time ....if i am inserting multiple records also. what can be the reason ? why not coming here
                   note: type__c : formula fiel
 TypeAmountMap this map is having value type__c and amount__c which every time getting populated.

Please help me
Snippet code related to named credential
Http h = new Http();
HttpRequest req = new HttpRequest(); req.setEndpoint('callout:Test/dwsso/oauth2/access_token'); req.setMethod('POST'); req.setBody('grant_type=password&username=tfeldmeier%40pfsweb.com&password={!HTMLENCODE($Credential.Password)}'); string username = ***********'; string password = 'GmmR2fH2S@A7'; req.setHeader('Content-Type', 'application/x-www-form-urlencoded'); Blob headerValue = Blob.valueOf(username + ':' +password); String authHeader = 'BASIC' +Encodingutil.base64encode(headerValue); req.setHeader('Authorization',authHeader); HttpResponse resp = h.send(req); System.debug('response'+resp.getBody());```
please take on look on screenshot as well 



It is giving error
response{"error_description":"Client authentication failed","error":"invalid_client"}

Hi there,

I need to add list of lead in campaign member.
here is my code.

public class leadUtil {
public static void addInCampaign(List<Lead> leads){
        Campaign c = [Select id from Campaign limit 1];
        for(lead l:leads){ 
        CampaignMember mem = new CampaignMember (campaignid=c.id, leadid=l.id);  
        insert mem;