• Ryan Meyer
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 8
    Replies

Hi - I have a basic trigger that works as follows: user types in HKG in a field and the trigger searches for airport__c records matching HKG and attaches them to a lookup field. I'm trying to add an error in case the IATA code (HKG) is not found, but it doesn't seem to be working. Am I putting it in the wrong place? Do I just make a if lookup__c is null adderror? Thank you very much for any assistance! 

 

trigger ABInboundAirportMapping on Airline_Booking__c (before insert,before update) 
{
    Set<String> airportNames = new Set<String>();
       for(Airline_Booking__c AB: trigger.new){
                 AirportNames.add(AB.Inbound_Airport__c);
       }
     List<Airport__c> airports = [SELECT Id, Name FROM  Airport__c WHERE Name IN : airportNames ];


      for (Airline_Booking__c AB : Trigger.new) {
       for( Airport__c ar : airports ){
                 if(ar.Name == AB.Inbound_Airport__c){
                             AB.Inbound_Airport_Lookup__c = ar.Id;
                 }
                 else { AB.addError('Unable to find inbound airport with that IATA code.'); } 
        }
    }

}

Beating my head against the wall and hoping someone can point out what I'm missing. I have a basic Lightning component with a drop-down. When that drop-down changes, I'd like the controller to make a second field visible through an aura if. But I can't even get the selection onchange to trigger. 

 

Component is basically:

<aura:attribute name="rType" type="string"/>  
<lightning:select name="rType" label="Record Type" value="{!v.rType}" required="true" onchange="{!c.syncSelection}">

With controller:

syncSelection: function (component, event, helper) {
        console.log("this worked");

 

Hi,

I have a controller for a page which does a http callout with the visitor's IP address to show their location. Page works great but I can't seem to get testing to work. I have a mock callout class that works for other classes but when I try to use it on this I receive the error "Methods defined as TestMethod do not support Web service callouts" -- is this because it's a controller and not a class?  Any help would be appreciated here.. banging my head against the table!

Relevant controlller excerpt:
 
public class CC_Auth_Class{
   public CC_Auth_Class(ApexPages.StandardController controller) {
    String strCity;
        String strRegion;
        String strCountry;
        Http httpProtocol = new Http();
        HttpRequest request = new HttpRequest();
        String endpoint = 'http://ipinfo.io/'+ApexPages.currentPage().getHeaders().get('X-Salesforce-SIP')+'/json';
        request.setEndPoint(endpoint);
        request.setMethod('GET');
        HttpResponse response = httpProtocol.send(request);
        JSONParser parser = JSON.createParser(response.getBody());
        while (parser.nextToken() != null) {
            if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'city')) {
                parser.nextToken();
                strCity = parser.getText();
            }
            if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'region')) {
                parser.nextToken();
                strRegion = parser.getText();
            }
            if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'country')) {
                parser.nextToken();
                strCountry = parser.getText();
            }
            }
        card.AUTH_LOCATION__c = strCity+', '+strregion+', '+strcountry;
    }
}



relevant test... where O = dummy opp 
ApexPages.StandardController sc = new ApexPages.StandardController(O);
        CC_Auth_Class AuthClass = new CC_Auth_Class(sc);
        PageReference pageRef = Page.CC_Auth_Form;
        pageRef.getParameters().put('id', String.valueOf(O.Id));
        Test.setMock(HttpCalloutMock.class, new FakeHTTPPost());
        Test.setCurrentPage(pageRef);

       

Hello, 

I have the following apex class scheduled to run daily. It says it executes, but there is nothing in the logs at that time even using the finest settings, and the intended result (bounced leads stop getting emails) doesn't happen. I'm sure it's something obvious but I'm bashing my head against the wall. Not only is there a lead with a bounced email, but I specifically created a Test Test lead with no success. Any help would be greatly appreciated.

SCHEDULED CLASS:

public class ScheduleStopEmailingBouncedLeadsBatch implements Schedulable {
    public void execute(SchedulableContext ctx) {
        StopEmailingBouncedLeadsBatch SEBL = new StopEmailingBouncedLeadsBatch();
    Database.executeBatch(SEBL,200);
    }
}

CALLED CLASS:

 

public class StopEmailingBouncedLeadsBatch implements Database.Batchable<sObject>{
    public Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator('select id from lead where (emailbounceddate=yesterday and hasoptedoutofemail=false) or name=\'Test Test\''); 
    }
    public void execute(Database.BatchableContext bc, List<Lead> Leads){
        try{
            for(Lead L : Leads)
                L.HasOptedOutOfEmail=true;
        }
        Catch(Exception e){
            system.debug('Exception occured -->'+E.getMessage()+' at line '+e.getLineNumber());
        }
    }    
    public void finish(Database.BatchableContext bc){
        
    }    
}

Hello, 

I have a simple apex class that looks up unassigned leads (the # currently in the default queue) and posts the current count to Slack via webhook. The class works fine, however, I scheduled it to run twice per day and it keeps posting the same number each time -- what I believe is the number of leads that were in the queue at the time of scheduling... not at the time it runs.

I'm not sure if I'm completely missing something here or what, but I don't see how/why that would be the case. Also... how do I get around this? Create a class to schedule which simply calls the other class? Code below...

Thank you! 
 
public class PostLeadCounttoSlack implements schedulable { 

    private static final String slackURL = 'https://hooks.slack.com/services/T0xxxxxxxxxxxxxxxxxxxxxxx';
    AggregateResult res = [SELECT count(id) From Lead where OwnerId in (SELECT Id from Group where type='Queue' and Name='Default Lead Queue')];
    Integer lc = integer.valueof(res.get('expr0'));

    public void execute(SchedulableContext sc){

    Map<String,Object> msg = new Map<String,Object>();
        msg.put('text', 'There are ' + lc + ' leads in the queue.');
        msg.put('mrkdwn', true);
        msg.put('link_names', '1');
        String body = JSON.serialize(msg);    
        System.enqueueJob(new QueueableSlackCall(slackURL, 'POST', body));
    }

    public class QueueableSlackCall implements System.Queueable, Database.AllowsCallouts {
         
        private final String url;
        private final String method;
        private final String body;
         
        public QueueableSlackCall(String url, String method, String body) {
            this.url = url;
            this.method = method;
            this.body = body;
        }
         
        public void execute(System.QueueableContext ctx) {
            HttpRequest req = new HttpRequest();
            req.setEndpoint(url);
            req.setMethod(method);
            req.setBody(body);
            Http http = new Http();
            HttpResponse res = http.send(req);
        }
 
    }    
}

Beating my head against the wall and hoping someone can point out what I'm missing. I have a basic Lightning component with a drop-down. When that drop-down changes, I'd like the controller to make a second field visible through an aura if. But I can't even get the selection onchange to trigger. 

 

Component is basically:

<aura:attribute name="rType" type="string"/>  
<lightning:select name="rType" label="Record Type" value="{!v.rType}" required="true" onchange="{!c.syncSelection}">

With controller:

syncSelection: function (component, event, helper) {
        console.log("this worked");

 

Beating my head against the wall and hoping someone can point out what I'm missing. I have a basic Lightning component with a drop-down. When that drop-down changes, I'd like the controller to make a second field visible through an aura if. But I can't even get the selection onchange to trigger. 

 

Component is basically:

<aura:attribute name="rType" type="string"/>  
<lightning:select name="rType" label="Record Type" value="{!v.rType}" required="true" onchange="{!c.syncSelection}">

With controller:

syncSelection: function (component, event, helper) {
        console.log("this worked");

 

Hi,

I have a controller for a page which does a http callout with the visitor's IP address to show their location. Page works great but I can't seem to get testing to work. I have a mock callout class that works for other classes but when I try to use it on this I receive the error "Methods defined as TestMethod do not support Web service callouts" -- is this because it's a controller and not a class?  Any help would be appreciated here.. banging my head against the table!

Relevant controlller excerpt:
 
public class CC_Auth_Class{
   public CC_Auth_Class(ApexPages.StandardController controller) {
    String strCity;
        String strRegion;
        String strCountry;
        Http httpProtocol = new Http();
        HttpRequest request = new HttpRequest();
        String endpoint = 'http://ipinfo.io/'+ApexPages.currentPage().getHeaders().get('X-Salesforce-SIP')+'/json';
        request.setEndPoint(endpoint);
        request.setMethod('GET');
        HttpResponse response = httpProtocol.send(request);
        JSONParser parser = JSON.createParser(response.getBody());
        while (parser.nextToken() != null) {
            if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'city')) {
                parser.nextToken();
                strCity = parser.getText();
            }
            if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'region')) {
                parser.nextToken();
                strRegion = parser.getText();
            }
            if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'country')) {
                parser.nextToken();
                strCountry = parser.getText();
            }
            }
        card.AUTH_LOCATION__c = strCity+', '+strregion+', '+strcountry;
    }
}



relevant test... where O = dummy opp 
ApexPages.StandardController sc = new ApexPages.StandardController(O);
        CC_Auth_Class AuthClass = new CC_Auth_Class(sc);
        PageReference pageRef = Page.CC_Auth_Form;
        pageRef.getParameters().put('id', String.valueOf(O.Id));
        Test.setMock(HttpCalloutMock.class, new FakeHTTPPost());
        Test.setCurrentPage(pageRef);

       

Hello, 

I have the following apex class scheduled to run daily. It says it executes, but there is nothing in the logs at that time even using the finest settings, and the intended result (bounced leads stop getting emails) doesn't happen. I'm sure it's something obvious but I'm bashing my head against the wall. Not only is there a lead with a bounced email, but I specifically created a Test Test lead with no success. Any help would be greatly appreciated.

SCHEDULED CLASS:

public class ScheduleStopEmailingBouncedLeadsBatch implements Schedulable {
    public void execute(SchedulableContext ctx) {
        StopEmailingBouncedLeadsBatch SEBL = new StopEmailingBouncedLeadsBatch();
    Database.executeBatch(SEBL,200);
    }
}

CALLED CLASS:

 

public class StopEmailingBouncedLeadsBatch implements Database.Batchable<sObject>{
    public Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator('select id from lead where (emailbounceddate=yesterday and hasoptedoutofemail=false) or name=\'Test Test\''); 
    }
    public void execute(Database.BatchableContext bc, List<Lead> Leads){
        try{
            for(Lead L : Leads)
                L.HasOptedOutOfEmail=true;
        }
        Catch(Exception e){
            system.debug('Exception occured -->'+E.getMessage()+' at line '+e.getLineNumber());
        }
    }    
    public void finish(Database.BatchableContext bc){
        
    }    
}

Hello, 

I have a simple apex class that looks up unassigned leads (the # currently in the default queue) and posts the current count to Slack via webhook. The class works fine, however, I scheduled it to run twice per day and it keeps posting the same number each time -- what I believe is the number of leads that were in the queue at the time of scheduling... not at the time it runs.

I'm not sure if I'm completely missing something here or what, but I don't see how/why that would be the case. Also... how do I get around this? Create a class to schedule which simply calls the other class? Code below...

Thank you! 
 
public class PostLeadCounttoSlack implements schedulable { 

    private static final String slackURL = 'https://hooks.slack.com/services/T0xxxxxxxxxxxxxxxxxxxxxxx';
    AggregateResult res = [SELECT count(id) From Lead where OwnerId in (SELECT Id from Group where type='Queue' and Name='Default Lead Queue')];
    Integer lc = integer.valueof(res.get('expr0'));

    public void execute(SchedulableContext sc){

    Map<String,Object> msg = new Map<String,Object>();
        msg.put('text', 'There are ' + lc + ' leads in the queue.');
        msg.put('mrkdwn', true);
        msg.put('link_names', '1');
        String body = JSON.serialize(msg);    
        System.enqueueJob(new QueueableSlackCall(slackURL, 'POST', body));
    }

    public class QueueableSlackCall implements System.Queueable, Database.AllowsCallouts {
         
        private final String url;
        private final String method;
        private final String body;
         
        public QueueableSlackCall(String url, String method, String body) {
            this.url = url;
            this.method = method;
            this.body = body;
        }
         
        public void execute(System.QueueableContext ctx) {
            HttpRequest req = new HttpRequest();
            req.setEndpoint(url);
            req.setMethod(method);
            req.setBody(body);
            Http http = new Http();
            HttpResponse res = http.send(req);
        }
 
    }    
}
Hello Everyone,

I'm Integrating braitree payment gateway in salesfore using REST API. But I'm not getting the desired result. Please tell me what is missing in my code which is mentioned below:
 
<!-- Visualforce Page -->
<apex:page controller="braintreeConfig" standardstylesheets="false" applyHtmlTag="false" applybodytag="false" cache="false" showheader="false" doctype="html-5.0" title="Braintree">
  <apex:form >
      <apex:outputPanel id="main">      
          {!str}
      </apex:outputPanel>
      <apex:commandButton value="Click" action="{!click}" rerender="main" oncomplete="myfunc()"/>      
  </apex:form>  
</apex:page>


<!-- Controller -->
public with sharing class braintreeConfig{

    public string str{get;set;} 
    public void click(){
        try{
        
            HttpRequest req = new HttpRequest();
            req.setEndpoint('https://api.sandbox.braintreegateway.com:443/merchants/qhbgvbfxxsqdrbtj/client_token/?version=2');
            req.setMethod('POST');
            
            
            map<string,string> mp = new map<string,string>();
            mp.put('[environment:Braintree\\Configuration:private]', 'sandbox');
            mp.put('[merchantId:Braintree\\Configuration:private]', 'qhbgvbfxxsqdrbtj');
            mp.put('[publicKey:Braintree\\Configuration:private]', '52nztrwwvp8zvqg8');
            mp.put('[privateKey:Braintree\\Configuration:private]', 'f17db5318738459ca0278906181d5aa8');
            mp.put('[_clientId:Braintree\\Configuration:private]', '');
            mp.put('[_clientSecret:Braintree\\Configuration:private]', '');
            mp.put('[_accessToken:Braintree\\Configuration:private]', '');
            mp.put('[_proxyHost:Braintree\\Configuration:private]', '');
            mp.put('[_proxyPort:Braintree\\Configuration:private]', '');
            mp.put('[_proxyType:Braintree\\Configuration:private]', '');
            mp.put('[_proxyUser:Braintree\\Configuration:private]', '');
            mp.put('[_proxyPassword:Braintree\\Configuration:private]', '');
            mp.put('[timeout:Braintree\\Configuration:private]', '60');
            mp.put('[acceptGzipEncoding:Braintree\\Configuration:private]', '1');
            mp.put('[_useClientCredentials:Braintree\\Http:private]', '');
            
            req.setBody(JSON.serialize(mp));
            
            Http http = new Http();
            HTTPresponse res= http.send(req);
            str = res.getBody();
            
        }catch(exception e){
            system.debug(e);
        }
    }   
    
}

I'm getting the response mentioned in screenshot.
https://qsnapnet.com/snaps/o1bn133wd5z5mi 

Please Help me out with this.

Thanks In Advance
Aakanksha Singh