• Baylor Peak
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 22
    Replies

Hello all,

I am storing my enpoint for a REST callout inside a custom setting called MyCustomSettings with Name of 'default'. One of the fields inside the custom setting is a type URL field called 'endpoint' with 'test.com' for the value.

In my code, I have:

MyCustomSettings__c myCS1=MyCustomSettings__c.getValues('default');
        string endpoint=myCS1.endpoint__c;
		request.setHeader('Authorization',authorizationHeader);
		request.setHeader('Content-Type','application/json');
		request.setEndpoint(endpoint);

When I test my code I am getting this error:

System.NullPointerException: Argument 1 cannot be null

What am I missing please?:)

 

Hello all,

I wrote a batch class that sends data to an endpoint but I am not good with test classes at all:(

Here is my code:

global class CircleMembershipBatchProcesor implements Database.Batchable<sObject>, Database.AllowsCallouts, Database.Stateful {
    
// Start Method
    global Integer recordsProcessed = 0;
    global Database.QueryLocator start(Database.BatchableContext bc) {
        String apexClassId = '01p1U00000QoPw6QAF';
        List<AsyncApexJob> jobs = [SELECT CreatedDate FROM AsyncApexJob WHERE JobType = 'BatchApex' AND ApexClassId =: apexClassId ORDER BY CreatedDate DESC LIMIT 1];
        DateTime jobDate = null;
        if (jobs != null && jobs.size() > 0) {
            System.debug('using AsyncApexJob');
            AsyncApexJob job = jobs[0];
            jobDate = job.CreatedDate;
        } else {
            System.debug('using System.now()');
            jobDate = System.now().addHours(-1);
        }
        String dateStr = jobDate.format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ');
        System.debug(dateStr);
        String Query='SELECT Id, FirstName, LastName, Email, npo02__MembershipJoinDate__c, npo02__MembershipEndDate__c, npo02__LastMembershipDate__c FROM Contact WHERE npo02__MembershipJoinDate__c != NULL AND (CreatedDate > ' + dateStr + ' OR LastModifiedDate > ' + dateStr + ')';
        return Database.getQueryLocator(Query);
    }
// Execute Method
    global void execute(Database.BatchableContext bc, List<Contact> scope){
        String JSONString = JSON.serialize(scope);
        HttpRequest request = new HttpRequest();
        HttpResponse response = new HttpResponse();
        Http http = new Http();

	// Retrieve username and password from Custom Setting
        CircleMembershipBatchSettings__c myCS1 = CircleMembershipBatchSettings__c.getValues('default');
        String username = myCS1.username__c;
        String password = myCS1.password__c;

    // Add basic authentication to header        
        // Create blob of user:pass
        Blob headerValue = Blob.valueOf(username + ':' + password);
        // Base 64 Encode the blob and prepend "Basic "
        String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
        // Add the basic auth string to the Request Header
        request.setHeader('Authorization', authorizationHeader);

        request.setHeader('Content-Type', 'application/json');
        request.setEndpoint('https://th-webhook-test.herokuapp.com/webhook');
        request.setMethod('POST');
        request.setBody(JSONString);
        response = http.send(request);
        if (response.getStatusCode() == 200) {
            String jsonResponse = response.getBody();
            System.debug('Response-' + jsonResponse);
            System.debug(JSONString);
        } else {
            throw new CircleMembershipBatchProcesorException('Callout was not successful');
        }
    }
// Finish Method
    global void finish(Database.BatchableContext bc){
        Id job= bc.getJobId();
        System.debug(job);
    }
}

Hello all,

Trying to find a clean method via SOQL to query only records that were updated/created since the last executed apex batch job completed?

We are hoping not to have to create a custom object to do this and looking for a clean way if possible:)

Hello all,

I have a user who is consistently making API calls to Salesforce, but I am unable to figure out what records he is creating. Under his Contact, he has 0 records, yet he is making several API calls to Salesforce on a daily basis.

Is there a way to query on whether or not a record was generated from an API call from an external system?

Regards,
Baylor Peak

Hello all,

I am still pretty new to Salesforce admin and APIs in general but I have an admin we need to deactivate and stop all his access, transfer any record ownership, workflows, locate any APEX code he created.
 
I checked and I can't find any records under their username and can't find any records or APEX they created or have any ownership of those records, but they are accessing the API on a consistent basis.

So, first, how can I see what they are doing via the API, where are those records or what code is creating them, etc? How can I see excactly what they are doing each time they access the API? I checked the login history and see it's all SOAP Enterprise but I can't find where the source login is, what they are creating in Salesforce, etc?

Seconnly, If I deactivate them and revoke their access to all listed oAuth apps, will that stop their ability to access the API, and prevent them from accessing our org in any way etc?

Hello all,

I am able to query all the active users in a specific profile:

select user.id, user.FirstName, user.LastName, user.profile.name, user.Username, user.IsActive FROM user, user.profile where profile.name = 'xxxxx' AND IsActive=True


That just returns the active users for the profile, but I am trying to query only the active system admins in a specific profie.

What am I doing wrong please?:)

 

Hello all,

I finally got my Trigger to do what I want, almost...

I ran into a snag that I can't figure out why it's occuring.

I've notcied that my Total Touchpoint fields are not reflecting correctly when there are no Activities under Activity History. So let's say Total Contacs is showing 10, I can add and delete Tasks and it updates correctly until I delete the last Task. Once I delete the last Task under Activity History, it leaves 1 for the Total Contacts field.

Beating my head around this....

Here is my whole code and I would love some input on whay it's not working like it should be unless I am missing something?:D

trigger TaskRollupSummaryTrigger on Task (after insert, after update, after delete) {
    Set<ID> contactIdSet = new Set<ID>();
    if(Trigger.isInsert || Trigger.isupdate){
        for (Task t : trigger.new) {
            if (t.whoId != NULL) {
                contactIdSet.add(t.whoId);
            }
        }
    }

    if(Trigger.isDelete){
        For(Task t : trigger.old){
            contactIdSet.add(t.whoId);
        }
    }
    
    if (contactIdSet.size() > 0) {
        AggregateResult[] groupedResults = [SELECT WhoId, Type, Count(ID) FROM Task WHERE WhoId IN :contactIdSet AND Type IN ('Call','Email','In-Person Meeting') GROUP BY WhoId, Type];
        
        Map<ID, Contact> contactMap = new Map<ID, Contact>([SELECT Id, Total_Call_Touchpoints__c FROM Contact WHERE Id IN :contactIdSet]);
    
        for (AggregateResult g : groupedResults) {    
            System.debug('####' + g.get('WhoId') + ' : ' + g.get('expr0'));
            Contact c = contactMap.get((String)g.get('WhoId'));
            
            if ((String)g.get('Type') == 'Call') {
                c.Total_Call_Touchpoints__c = (Decimal)g.get('expr0');
            } else if ((String)g.get('Type') == 'Email') {
                c.Total_Email_Touchpoints__c = (Decimal)g.get('expr0');
            } else if ((String)g.get('Type') == 'In-Person Meeting') {
                c.Total_Meeting_Touchpoints__c = (Decimal)g.get('expr0');
            }
        }
        update contactMap.values();
    }
}

Regards for all your help:)
Helo all,

I have a Trigger that does a rollup of different Touchpoints on a Task. One of these Touchpoints is "Email".

What's happening is on an Insert/Update/Delete, the filed is recalculated with teh total numbert of Email Activities, except for those that came from an Outbound source via Email to Salesforce.

User-added image
So these Outbound emails are generated an an Activity and I want to be able to include the count of these Outbound Email Messages in my Total Email Touchpoints rollup.

Is this possible, becasue I am havinmg trouble trying to figure out what Object associated with External emails sent to Saleforce so I can just quertry on that object to get my number?

Regards,
Baylor

Hello all,

I am still getting my feet wet with Apex but have come a good way, but still would be very gracilous for this awesome community's input please:)

I have a Trigger on Task after activities are either inserted or updated that performs a rollup for touchpoints on open activities.

The issue is if a user deletes an activity, the rollup is unaffected resulting in an erroneus count for the touchpoints.

This is my code:

trigger TaskRollupSummaryTrigger on Task (after insert, after update) {
    Set<ID> contactIdSet = new Set<ID>();

    for (Task t : trigger.new) {
        if (t.whoId != NULL) {
            contactIdSet.add(t.whoId);
        }
    }
    
    if (contactIdSet.size() > 0) {
        AggregateResult[] groupedResults = [SELECT WhoId, Type, Count(ID) FROM Task WHERE WhoId IN :contactIdSet AND Type IN ('Call','Email','In-Person Meeting') GROUP BY WhoId, Type];
        
        Map<ID, Contact> contactMap = new Map<ID, Contact>([SELECT Id, Total_Call_Touchpoints__c FROM Contact WHERE Id IN :contactIdSet]);
    
        for (AggregateResult g : groupedResults) {    
            System.debug('####' + g.get('WhoId') + ' : ' + g.get('expr0'));
            Contact c = contactMap.get((String)g.get('WhoId'));
            
            if ((String)g.get('Type') == 'Call') {
                c.Total_Call_Touchpoints__c = (Decimal)g.get('expr0');
            } else if ((String)g.get('Type') == 'Email') {
                c.Total_Email_Touchpoints__c = (Decimal)g.get('expr0');
            } else if ((String)g.get('Type') == 'In-Person Meeting') {
                c.Total_Meeting_Touchpoints__c = (Decimal)g.get('expr0');
            }
        }
        update contactMap.values();
    }
}

First question is why isn't the SELECT counting acxtivities that have been deleted?

Is there a way to get the trigger to see when activities are deleted and refelct that in the ttouchpoint rollups?

Hello all,

I am storing my enpoint for a REST callout inside a custom setting called MyCustomSettings with Name of 'default'. One of the fields inside the custom setting is a type URL field called 'endpoint' with 'test.com' for the value.

In my code, I have:

MyCustomSettings__c myCS1=MyCustomSettings__c.getValues('default');
        string endpoint=myCS1.endpoint__c;
		request.setHeader('Authorization',authorizationHeader);
		request.setHeader('Content-Type','application/json');
		request.setEndpoint(endpoint);

When I test my code I am getting this error:

System.NullPointerException: Argument 1 cannot be null

What am I missing please?:)

 

Hello all,

I wrote a batch class that sends data to an endpoint but I am not good with test classes at all:(

Here is my code:

global class CircleMembershipBatchProcesor implements Database.Batchable<sObject>, Database.AllowsCallouts, Database.Stateful {
    
// Start Method
    global Integer recordsProcessed = 0;
    global Database.QueryLocator start(Database.BatchableContext bc) {
        String apexClassId = '01p1U00000QoPw6QAF';
        List<AsyncApexJob> jobs = [SELECT CreatedDate FROM AsyncApexJob WHERE JobType = 'BatchApex' AND ApexClassId =: apexClassId ORDER BY CreatedDate DESC LIMIT 1];
        DateTime jobDate = null;
        if (jobs != null && jobs.size() > 0) {
            System.debug('using AsyncApexJob');
            AsyncApexJob job = jobs[0];
            jobDate = job.CreatedDate;
        } else {
            System.debug('using System.now()');
            jobDate = System.now().addHours(-1);
        }
        String dateStr = jobDate.format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ');
        System.debug(dateStr);
        String Query='SELECT Id, FirstName, LastName, Email, npo02__MembershipJoinDate__c, npo02__MembershipEndDate__c, npo02__LastMembershipDate__c FROM Contact WHERE npo02__MembershipJoinDate__c != NULL AND (CreatedDate > ' + dateStr + ' OR LastModifiedDate > ' + dateStr + ')';
        return Database.getQueryLocator(Query);
    }
// Execute Method
    global void execute(Database.BatchableContext bc, List<Contact> scope){
        String JSONString = JSON.serialize(scope);
        HttpRequest request = new HttpRequest();
        HttpResponse response = new HttpResponse();
        Http http = new Http();

	// Retrieve username and password from Custom Setting
        CircleMembershipBatchSettings__c myCS1 = CircleMembershipBatchSettings__c.getValues('default');
        String username = myCS1.username__c;
        String password = myCS1.password__c;

    // Add basic authentication to header        
        // Create blob of user:pass
        Blob headerValue = Blob.valueOf(username + ':' + password);
        // Base 64 Encode the blob and prepend "Basic "
        String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
        // Add the basic auth string to the Request Header
        request.setHeader('Authorization', authorizationHeader);

        request.setHeader('Content-Type', 'application/json');
        request.setEndpoint('https://th-webhook-test.herokuapp.com/webhook');
        request.setMethod('POST');
        request.setBody(JSONString);
        response = http.send(request);
        if (response.getStatusCode() == 200) {
            String jsonResponse = response.getBody();
            System.debug('Response-' + jsonResponse);
            System.debug(JSONString);
        } else {
            throw new CircleMembershipBatchProcesorException('Callout was not successful');
        }
    }
// Finish Method
    global void finish(Database.BatchableContext bc){
        Id job= bc.getJobId();
        System.debug(job);
    }
}
Hello all,

I have a user who is consistently making API calls to Salesforce, but I am unable to figure out what records he is creating. Under his Contact, he has 0 records, yet he is making several API calls to Salesforce on a daily basis.

Is there a way to query on whether or not a record was generated from an API call from an external system?

Regards,
Baylor Peak

Hello all,

I am able to query all the active users in a specific profile:

select user.id, user.FirstName, user.LastName, user.profile.name, user.Username, user.IsActive FROM user, user.profile where profile.name = 'xxxxx' AND IsActive=True


That just returns the active users for the profile, but I am trying to query only the active system admins in a specific profie.

What am I doing wrong please?:)

 

Hello all,

I finally got my Trigger to do what I want, almost...

I ran into a snag that I can't figure out why it's occuring.

I've notcied that my Total Touchpoint fields are not reflecting correctly when there are no Activities under Activity History. So let's say Total Contacs is showing 10, I can add and delete Tasks and it updates correctly until I delete the last Task. Once I delete the last Task under Activity History, it leaves 1 for the Total Contacts field.

Beating my head around this....

Here is my whole code and I would love some input on whay it's not working like it should be unless I am missing something?:D

trigger TaskRollupSummaryTrigger on Task (after insert, after update, after delete) {
    Set<ID> contactIdSet = new Set<ID>();
    if(Trigger.isInsert || Trigger.isupdate){
        for (Task t : trigger.new) {
            if (t.whoId != NULL) {
                contactIdSet.add(t.whoId);
            }
        }
    }

    if(Trigger.isDelete){
        For(Task t : trigger.old){
            contactIdSet.add(t.whoId);
        }
    }
    
    if (contactIdSet.size() > 0) {
        AggregateResult[] groupedResults = [SELECT WhoId, Type, Count(ID) FROM Task WHERE WhoId IN :contactIdSet AND Type IN ('Call','Email','In-Person Meeting') GROUP BY WhoId, Type];
        
        Map<ID, Contact> contactMap = new Map<ID, Contact>([SELECT Id, Total_Call_Touchpoints__c FROM Contact WHERE Id IN :contactIdSet]);
    
        for (AggregateResult g : groupedResults) {    
            System.debug('####' + g.get('WhoId') + ' : ' + g.get('expr0'));
            Contact c = contactMap.get((String)g.get('WhoId'));
            
            if ((String)g.get('Type') == 'Call') {
                c.Total_Call_Touchpoints__c = (Decimal)g.get('expr0');
            } else if ((String)g.get('Type') == 'Email') {
                c.Total_Email_Touchpoints__c = (Decimal)g.get('expr0');
            } else if ((String)g.get('Type') == 'In-Person Meeting') {
                c.Total_Meeting_Touchpoints__c = (Decimal)g.get('expr0');
            }
        }
        update contactMap.values();
    }
}

Regards for all your help:)
Helo all,

I have a Trigger that does a rollup of different Touchpoints on a Task. One of these Touchpoints is "Email".

What's happening is on an Insert/Update/Delete, the filed is recalculated with teh total numbert of Email Activities, except for those that came from an Outbound source via Email to Salesforce.

User-added image
So these Outbound emails are generated an an Activity and I want to be able to include the count of these Outbound Email Messages in my Total Email Touchpoints rollup.

Is this possible, becasue I am havinmg trouble trying to figure out what Object associated with External emails sent to Saleforce so I can just quertry on that object to get my number?

Regards,
Baylor

Hello all,

I am still getting my feet wet with Apex but have come a good way, but still would be very gracilous for this awesome community's input please:)

I have a Trigger on Task after activities are either inserted or updated that performs a rollup for touchpoints on open activities.

The issue is if a user deletes an activity, the rollup is unaffected resulting in an erroneus count for the touchpoints.

This is my code:

trigger TaskRollupSummaryTrigger on Task (after insert, after update) {
    Set<ID> contactIdSet = new Set<ID>();

    for (Task t : trigger.new) {
        if (t.whoId != NULL) {
            contactIdSet.add(t.whoId);
        }
    }
    
    if (contactIdSet.size() > 0) {
        AggregateResult[] groupedResults = [SELECT WhoId, Type, Count(ID) FROM Task WHERE WhoId IN :contactIdSet AND Type IN ('Call','Email','In-Person Meeting') GROUP BY WhoId, Type];
        
        Map<ID, Contact> contactMap = new Map<ID, Contact>([SELECT Id, Total_Call_Touchpoints__c FROM Contact WHERE Id IN :contactIdSet]);
    
        for (AggregateResult g : groupedResults) {    
            System.debug('####' + g.get('WhoId') + ' : ' + g.get('expr0'));
            Contact c = contactMap.get((String)g.get('WhoId'));
            
            if ((String)g.get('Type') == 'Call') {
                c.Total_Call_Touchpoints__c = (Decimal)g.get('expr0');
            } else if ((String)g.get('Type') == 'Email') {
                c.Total_Email_Touchpoints__c = (Decimal)g.get('expr0');
            } else if ((String)g.get('Type') == 'In-Person Meeting') {
                c.Total_Meeting_Touchpoints__c = (Decimal)g.get('expr0');
            }
        }
        update contactMap.values();
    }
}

First question is why isn't the SELECT counting acxtivities that have been deleted?

Is there a way to get the trigger to see when activities are deleted and refelct that in the ttouchpoint rollups?