• Brian Chipman 4
  • NEWBIE
  • 40 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 18
    Replies
Is there a way to do this, preferrably using clicks, but can be code?  For example, we might have a picture attached to a Case record.  If a custom Service Order record is created from the Case, we would like that picure to be automatically attached to the newly created Service Order record.
Have a Detail Page Button on an object that open a Visualforce page in a new window.  How do I set the size and position of that new window?
Would like to create a class to POST some data on an endpoint provided by an outside vendor.  Am modeling it on the "Mighty Moose" Trailhead example (https://trailhead.salesforce.com/en/content/learn/modules/apex_integration_services/apex_integration_rest_callouts) and the only difference seems to be the endpoint, the existence of an "api_key" (which the vendor says should be part of the url), and am passing more than one field.  Looks simple, but I have never done this type of thing before.  

Am testing in the "Open Execute Anonymous Window" of the developer console.  The trailhead example works fine but I am always getting a 400 Bad Request error for the real call out.  I do have a Remote Site setting.

Anything in the code below you can see (some data changed for security reasons)?
Any code you think might work better?
Any questions or details I should ask the vendor?
The vendor says I should be getting an explanatory message, but in the debug log I only see '400 Bad Request' and some other seemingly unrelated stuff.
 
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://my.domain.com/icon/send_eligible_offers?api_key=abcd-1234');
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json;charset=UTF-8');

// Set the body as a JSON object
request.setBody('{"product_sku":"NTL07007", "serial_number":"1234343434", "user_email":"user.name@gmail.com", "sales_person_email":"agent@mail.com"}');

HttpResponse response = http.send(request);

// Parse the JSON response
if (response.getStatusCode() != 201) {
    System.debug('The status code returned was not expected: ' +
        response.getStatusCode() + ' ' + response.getStatus());
} else {
    System.debug(response.getBody());
}

 
Looking for a way to compactly display all chatter posts on a record in the standard view.  Perhaps a table with a couple of identifying fields and the body of the posts.  Was thinking of a vf page embedded in the layout using apex:relatedlist, but in that case, how would I reference the chatter object if possible?

Perhaps a vf page, embedded in the layout, but some other way to display chatter post records in a table?  Any code snippets, articles, examples, would be appreciated. If it looked like any other related list, perhaps with some scrolling in teh case of many posts, that would be great.
Example:  Standard Account details page in Classic.  Has Assets, Cases, and Part Orders related lists.  Is there any way to, on selection of an Asset, display only the Cases related to that selected Asset in the Cases related list?  And then so on when a Case is selected in the Cases related list only those Part Orders related to that Case display in the Part Orders related list?

Replace the related lists with VF pages on the standard details page - sample code?
Override the details page - sample code?
Already a standard feature in Lightning?
Have succesully created a test class previously.  However, now I have a trigger and a potential test class for that trigger based off some examples but I am not able to do Test | New Run.  I get a message "Add test methods to your test class" but am not sure how to do that in the case of a trigger.  Any help or sugggestions would be appreciated.

Here is the trigger:
trigger UpdateAssetFromSO on Service_Order__c (after update, after delete) {

    List<Id> idAssetList = new List<Id>();
    List<Asset> assetListToUpdate = new List<Asset>();
    
    if(trigger.isUpdate) {
        
        for (Service_Order__c so : trigger.new) {
            
            if(trigger.oldMap.get(so.Id).Total_Reimbursement_Amount__c == so.Total_Reimbursement_Amount__c) continue;
            
            idAssetList.add(so.Asset__c);
        }       
    }
    
    if(trigger.isDelete) {
        
        for (Service_Order__c so : trigger.old) {
                      
            idAssetList.add(so.Asset__c);
        }         
    }
    
    if(idAssetList.isEmpty()) return;
    
    for(Id id : idAssetList) {
        
        Asset asset = new Asset(Id = id);
        asset.SOChanged__c = true;
        
        assetListToUpdate.add(asset);
        
    }
    
    if(assetListToUpdate.size() > 0)
        Database.update(assetListToUpdate);
}

Here is the Test Class (test when the Labor field is updated and when the service order record is deleted):
@isTest(SeeAllData=true)

public class UpdateAssetFromSO_Test {

    public void DoIt(){
    
        //Create Service Orer to work with
        Service_Order__c so = new Service_Order__c(
           Account__c='001j0000016yvCrAAI',
           CurrencyIsoCode='USD-U.S. Dollar',
           Status__c='Open',
           Charge_To__c='11 - Logan',
           Labor_Reimbursement__c = 12.00
           );
           insert so;
        
        //Update Service Order Total Reimbursement Amount is a formula field so we update Labor to make it change.
        so.Labor_Reimbursement__c = 123.00;
        
        //Delete Service Order
        Delete so;
        
    } 
    
}

 
I can write a simple trigger to update fields on the same object.  However, I have requirements that I'm not having success with even though there are a few pertinent examples.  The requirements are:

1) When the Total_Reimbursement__c field is updated on a Service_Order__c custom object record, the SOChanged__c field on the related (Lookup) Asset record is set to true.

2) When a Service_Orders__c record is deleted,  the SOChanged__c field on the related (Lookup) Asset record is set to true.​

The goal of course is to be able to, especially in the case of 2) above, kick off a variety of flows/processes that we might create when a Service Order is deleted on the update of this field. 1) above of could be done in a workflow, but if I'm doing a trigger, might as well put it there too.  Anything to help get me on my way would be appreciated. 
We have a Visualforce page created for us a while ago which we would like to use to override the standard Account Detail page.  However, it uses a custom controller, like this:

<apex:page controller="My_CustomController">

When I go to Buttons, Links, and Actions for this object to the View action, the page does not appear in the drop down list of pages available for override use.  My understanding is because this page does not use the stand controller. Any way to get around this and use this page for override?

Ultimately, I would like to conditionally oveerride based on Profile and I think I can do that, but it seems like I need to override for everyone first as per the above but I can't seem to do that with this page.
 
Beginner with Apex and test classes. Only getting 60% coverage. Any suggestions? Here is the class:

public class SearchAccountCommunity {
    public string searchEmail {get; set;}
   
    public PageReference findAccount(){
        List<Account> accountId = [SELECT Id from Account WHERE PersonEmail =:searchEmail LIMIT 1];
        PageReference registerNew;
        if(!accountId.isEmpty()){
            string url = 'https://myOrg.force.com/Residential/AssetOverrideCommunity?Account_lkid='+ accountId[0].id;
            registerNew = new PageReference(url);
            registerNew.setRedirect(true);
            return registerNew;
        }
        return registerNew;
    }

}

Here is the test class:

@isTest
public class test_SearchAccountCommunity {
    static testmethod void vailidateFindAccount(){
        SearchAccountCommunity test = new SearchAccountCommunity();
        test.searchEmail = 'test.email@email.com';
        string resultUrl = 'https://myOrg.force.com/Residential/AssetOverrideCommunity?Account_lkid=001j0000014FpHVAA0&isdtp=p1';
        PageReference pageTest = test.findAccount();
        System.assertEquals(resultUrl, pageTest.getUrl());
    }
}
 
Would like to create a class to POST some data on an endpoint provided by an outside vendor.  Am modeling it on the "Mighty Moose" Trailhead example (https://trailhead.salesforce.com/en/content/learn/modules/apex_integration_services/apex_integration_rest_callouts) and the only difference seems to be the endpoint, the existence of an "api_key" (which the vendor says should be part of the url), and am passing more than one field.  Looks simple, but I have never done this type of thing before.  

Am testing in the "Open Execute Anonymous Window" of the developer console.  The trailhead example works fine but I am always getting a 400 Bad Request error for the real call out.  I do have a Remote Site setting.

Anything in the code below you can see (some data changed for security reasons)?
Any code you think might work better?
Any questions or details I should ask the vendor?
The vendor says I should be getting an explanatory message, but in the debug log I only see '400 Bad Request' and some other seemingly unrelated stuff.
 
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://my.domain.com/icon/send_eligible_offers?api_key=abcd-1234');
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json;charset=UTF-8');

// Set the body as a JSON object
request.setBody('{"product_sku":"NTL07007", "serial_number":"1234343434", "user_email":"user.name@gmail.com", "sales_person_email":"agent@mail.com"}');

HttpResponse response = http.send(request);

// Parse the JSON response
if (response.getStatusCode() != 201) {
    System.debug('The status code returned was not expected: ' +
        response.getStatusCode() + ' ' + response.getStatus());
} else {
    System.debug(response.getBody());
}

 
Have a Detail Page Button on an object that open a Visualforce page in a new window.  How do I set the size and position of that new window?
Would like to create a class to POST some data on an endpoint provided by an outside vendor.  Am modeling it on the "Mighty Moose" Trailhead example (https://trailhead.salesforce.com/en/content/learn/modules/apex_integration_services/apex_integration_rest_callouts) and the only difference seems to be the endpoint, the existence of an "api_key" (which the vendor says should be part of the url), and am passing more than one field.  Looks simple, but I have never done this type of thing before.  

Am testing in the "Open Execute Anonymous Window" of the developer console.  The trailhead example works fine but I am always getting a 400 Bad Request error for the real call out.  I do have a Remote Site setting.

Anything in the code below you can see (some data changed for security reasons)?
Any code you think might work better?
Any questions or details I should ask the vendor?
The vendor says I should be getting an explanatory message, but in the debug log I only see '400 Bad Request' and some other seemingly unrelated stuff.
 
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://my.domain.com/icon/send_eligible_offers?api_key=abcd-1234');
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json;charset=UTF-8');

// Set the body as a JSON object
request.setBody('{"product_sku":"NTL07007", "serial_number":"1234343434", "user_email":"user.name@gmail.com", "sales_person_email":"agent@mail.com"}');

HttpResponse response = http.send(request);

// Parse the JSON response
if (response.getStatusCode() != 201) {
    System.debug('The status code returned was not expected: ' +
        response.getStatusCode() + ' ' + response.getStatus());
} else {
    System.debug(response.getBody());
}

 
Looking for a way to compactly display all chatter posts on a record in the standard view.  Perhaps a table with a couple of identifying fields and the body of the posts.  Was thinking of a vf page embedded in the layout using apex:relatedlist, but in that case, how would I reference the chatter object if possible?

Perhaps a vf page, embedded in the layout, but some other way to display chatter post records in a table?  Any code snippets, articles, examples, would be appreciated. If it looked like any other related list, perhaps with some scrolling in teh case of many posts, that would be great.
I can write a simple trigger to update fields on the same object.  However, I have requirements that I'm not having success with even though there are a few pertinent examples.  The requirements are:

1) When the Total_Reimbursement__c field is updated on a Service_Order__c custom object record, the SOChanged__c field on the related (Lookup) Asset record is set to true.

2) When a Service_Orders__c record is deleted,  the SOChanged__c field on the related (Lookup) Asset record is set to true.​

The goal of course is to be able to, especially in the case of 2) above, kick off a variety of flows/processes that we might create when a Service Order is deleted on the update of this field. 1) above of could be done in a workflow, but if I'm doing a trigger, might as well put it there too.  Anything to help get me on my way would be appreciated. 
We have a Visualforce page created for us a while ago which we would like to use to override the standard Account Detail page.  However, it uses a custom controller, like this:

<apex:page controller="My_CustomController">

When I go to Buttons, Links, and Actions for this object to the View action, the page does not appear in the drop down list of pages available for override use.  My understanding is because this page does not use the stand controller. Any way to get around this and use this page for override?

Ultimately, I would like to conditionally oveerride based on Profile and I think I can do that, but it seems like I need to override for everyone first as per the above but I can't seem to do that with this page.
 
Beginner with Apex and test classes. Only getting 60% coverage. Any suggestions? Here is the class:

public class SearchAccountCommunity {
    public string searchEmail {get; set;}
   
    public PageReference findAccount(){
        List<Account> accountId = [SELECT Id from Account WHERE PersonEmail =:searchEmail LIMIT 1];
        PageReference registerNew;
        if(!accountId.isEmpty()){
            string url = 'https://myOrg.force.com/Residential/AssetOverrideCommunity?Account_lkid='+ accountId[0].id;
            registerNew = new PageReference(url);
            registerNew.setRedirect(true);
            return registerNew;
        }
        return registerNew;
    }

}

Here is the test class:

@isTest
public class test_SearchAccountCommunity {
    static testmethod void vailidateFindAccount(){
        SearchAccountCommunity test = new SearchAccountCommunity();
        test.searchEmail = 'test.email@email.com';
        string resultUrl = 'https://myOrg.force.com/Residential/AssetOverrideCommunity?Account_lkid=001j0000014FpHVAA0&isdtp=p1';
        PageReference pageTest = test.findAccount();
        System.assertEquals(resultUrl, pageTest.getUrl());
    }
}