• Ashish Keshari
  • NEWBIE
  • 414 Points
  • Member since 2015
  • Sr. Salesforce Developer
  • Bluewolf


  • Chatter
    Feed
  • 8
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 75
    Replies
Team,

I am looking for some info into sending records to an external API everytime an Account is created or updated.
It will not be a Batch Job, but instead a callout everytime account information changes.
Is it possible to do it from the salesforce layout itself,  without having to write a custom VF page for triggering the callout ?
( The reason I mentioned VF page route, because that is what I know).
I have already gone through the developer guide , so please don't reference that.
I am not looking for code , but the framework/algorithm to do it.

Any help will be appreicated.
Thanks!
 
public class CreateInvoice{
    
    public CreateInvoice(){
        
        List<Training__c> trainingList = new List<Training__c>();
        List<Facturatie__c> facturatieList = new List<Facturatie__c>();
        
        try {
        trainingList = [SELECT id , NAME, Startdatum__c,factuur_bedrijf__c,
                          (SELECT Cursist_Prijs__c, Training__c, Cursist__c,CreatedDate,Prijs_training__c,
                           korting__c,Id 
                           FROM Trainingen_Volgen__r ) 
                       FROM  Training__c 
                       WHERE id NOT IN (SELECT  Training__c FROM Facturatie__c)];
        }catch (Exception e) {
            System.debug('The following exception has occurred' + e.getMessage() +
                         'At line number :' + e.getLineNumber() + 'Error' +
                         e.getStackTraceString());
        }              
        if(!trainingList.IsEmpty()){
            
            for(Training__c trainingRecord : trainingList){
                
                if(!trainingRecord.Trainingen_Volgen__r.IsEmpty()){
                    
                    for(Cursist__c cursistRecord : trainingRecord.Trainingen_Volgen__r){
                        
                        Facturatie__c facturatieRecord = checkDate(cursistRecord,trainingRecord);
                        facturatieList.add(facturatieRecord);
                    }
                }   
            }

            if(!facturatieList.IsEmpty()){  
               try {
                   insert facturatieList;
                }catch (Exception e) {
                    System.debug('The following exception has occurred' + e.getMessage() +
                                 'At line number :' + e.getLineNumber() + 'Error' +
                                 e.getStackTraceString());
                }   
               
            }
        }   
    }
    
    public Facturatie__c checkDate(Cursist__c cursistRecord,Training__c trainingRecord){
        
        if(cursistRecord != null && trainingRecord != null){
            Date todaysDate = system.today();
            
            if( todaysDate.addDays(-21) >= trainingRecord.Startdatum__c 
                && todaysDate >= cursistRecord.CreatedDate 
                && todaysDate.addDays(-1) >= trainingRecord.Startdatum__c){
                
                Facturatie__c facturatieRecord = new Facturatie__c();
                
                facturatieRecord.Training__c = trainingRecord.Id;   
                facturatieRecord.Factuur_Datum__c = todaysDate;  
                facturatieRecord.Verval_datum__c = todaysDate.addDays(30);
                
                if(cursistRecord.Prijs_training__c != null &&  cursistRecord.korting__c != null){
                    facturatieRecord.Factuur_Bedrag__c = cursistRecord.Prijs_training__c - cursistRecord.korting__c;
                }else if(cursistRecord.Prijs_training__c != null && cursistRecord.korting__c == null){
                    facturatieRecord.Factuur_Bedrag__c = cursistRecord.Prijs_training__c;
                }else if(cursistRecord.Prijs_training__c == null && cursistRecord.korting__c != null){
                    facturatieRecord.Factuur_Bedrag__c = cursistRecord.korting__c ;
                }
                
                facturatieRecord.Korting__c =  cursistRecord.korting__c;
                facturatieRecord.cursist_prijs__c= cursistRecord.Cursist_Prijs__c ;
                facturatieRecord.Contactpersoon__c = cursistRecord.Cursist__c;
                facturatieRecord.Account__c = trainingRecord.factuur_bedrijf__c; 
                
                return facturatieRecord;
            }
        }
        
        return null;
    }
}
 
@isTest
public class CreateInvoiceTestClass{
    
    // Creating Test Data
   @isTest public static void testData(){
    
        Account account = new Account(Name = 'TestAccount1');  
        insert account;
        
        List<Training__c> trainingList = new List<Training__c>();
        for(integer counter=0;counter<20;counter++){
            
            Training__c trainingRecord = new Training__c();
            trainingRecord.name = 'TestRecord'+counter;
            trainingRecord.Startdatum__c = System.today().addDays(+2);
            trainingRecord.factuur_bedrijf__c = account.Id;
            trainingList.add(trainingRecord);
        }
        insert trainingList;
        
         List<Facturatie__c> facturatieList = new List<Facturatie__c>();
        for(integer counter=0;counter<20;counter++){
            
            Facturatie__c facturatieRecord = new Facturatie__c();
            facturatieRecord.name = 'TestRecord'+counter;
            facturatieRecord.Factuur_Bedrag__c = 1000;
            facturatieRecord.Training__c = trainingList[counter].Id;
            facturatieList.add(facturatieRecord);
        }

       for(integer counter=0;counter<20;counter++){
            
            Facturatie__c facturatieRecord = new Facturatie__c();
            facturatieRecord.name = 'TestRecord2'+counter;
            facturatieRecord.Factuur_Bedrag__c = 1000;
            facturatieRecord.Training__c = trainingList[counter].Id;
            facturatieList.add(facturatieRecord);
        }
  
       insert facturatieList;

       
        List<Cursist__c> cursistList = new List<Cursist__c>();
        for(integer counter=0;counter<20;counter++){
            
            Cursist__c cursistRecord = new Cursist__c();           
            cursistRecord.Training__c = trainingList[counter].Id;
            cursistRecord.Prijs_training__c = 10;
            cursistRecord.korting__c = 10;
            cursistRecord.CreatedDate = System.today();
            cursistList.add(cursistRecord);
        }
        insert cursistList;
       
       system.debug(facturatieList[0].Account__c);
       Test.StartTEst();
	   CreateInvoice createInv = new CreateInvoice();
	   Test.stopTest();
      
       System.assertEquals(facturatieList[0].Account__c,null);
       
    }
   
}

User-added image
Hey all,

I'm trying to use Apex Trigger to populate a Shipping Address from the Billing Address if no Shipping Country is provided. However, I have a validation rule in place that requires the Shipping Country to be filled out before Account creation. From what I read, before triggers should fire before validation rules. However, I keep getting the validation rule error message when trying to create an Account with a Billing Address but no Shipping Address.

Here's the code:
trigger AccountShippingAddressUpdate on Account (before insert) {
    for (Account a : trigger.new)
    {
        if(a.ShippingCountry == '')
        {
            a.ShippingCity = a.BillingCity;
            a.ShippingCountry = a.BillingCountry;
            a.ShippingCountryCode = a.BillingCountryCode;
            a.ShippingState = a.BillingState;
            a.ShippingStateCode = a.BillingStateCode;
            a.ShippingStreet = a.BillingStreet;
            a.ShippingPostalCode = a.BillingPostalCode;
        }
    }
}

Thanks in advance!
Hello,

I have currently created the below web-to-lead form but I am having trouble with a couple things. What code/script would I need to input to ensure the email field does not allow email addresses from gmail, yahoo, hotmail, etc...? Also, how do I make certain fields like first name, last name, email, and web site required fields?

<form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST">

<input type=hidden name="oid" value="00Dc0000003kLYk">
<input type=hidden name="retURL" value="http://streamlinx.com/thank-you/">

<!--  ----------------------------------------------------------------------  -->
<!--  NOTE: These fields are optional debugging elements. Please uncomment    -->
<!--  these lines if you wish to test in debug mode.                          -->
<!--  <input type="hidden" name="debug" value=1>                              -->
<!--  <input type="hidden" name="debugEmail"                                  -->
<!--  value="example@example.com(for privacy purposes)">                                    -->
<!--  ----------------------------------------------------------------------  -->

<label for="first_name">First Name</label><input  id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br>

<label for="last_name">Last Name</label><input  id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br>

<label for="phone">Phone</label><input  id="phone" maxlength="40" name="phone" size="20" type="text" /><br>

<label for="email">Email</label><input  id="email" maxlength="80" name="email" size="20" type="text" /><br>

<label for="company">Company</label><input  id="company" maxlength="40" name="company" size="20" type="text" /><br>

<label for="city">City</label><input  id="city" maxlength="40" name="city" size="20" type="text" /><br>

<label for="state">State/Province</label><input  id="state" maxlength="20" name="state" size="20" type="text" /><br>

<label for="URL">Website</label><input  id="URL" maxlength="80" name="URL" size="20" type="text" /><br>

<input id="00N80000005owbR" name="00N80000005owbR" type="hidden"><br>

<input type="submit" name="submit">

</form>
Hello Folks,

I'm trying to add next/previous/first/last - the pageinitiations on a Custom Controller page. But while clicing the button, I'm getting below error 

System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!last}' in component <apex:commandButton> in page cus_message: Class.cus_message.last: line 31, column 1
Class.cus_message.last: line 31, column 1


Can someone please help to resolve the same.

Controller Code 

public class cus_message 
{
    List<Account> acts =new List<account>();
   
   public ApexPages.StandardSetController con {
        get;
        set;
    }
   
    public List<Account> getHigh_revenue_List()
    {
        acts =[select name,phone,industry,type,AnnualRevenue from Account where AnnualRevenue>50000];
        system.debug('inside high revenue');
        return acts;
    }
    
    Public List<Account> getLow_revenue_List()
    {
       
        acts =[select name,phone,industry,type,AnnualRevenue from Account where AnnualRevenue = NULL];
        system.debug('inside low revenue');
        return acts;
    }
    
    public void first() {
        this.con.first();
    }

    // returns the last page of records
    public void last() {
        this.con.last();        
    }

    // returns the previous page of records
    public void previous() { 
        this.con.previous();
    }

    // returns the next page of records
    public void next() {
        this.con.next();
    }
   
}

Visualforce Page 

<apex:page controller="cus_message">
<apex:form >
    <apex:pageBlock id="block_ID">
    <apex:pageblockButtons >
        <apex:commandButton value="Next Page" action="{!next}"/>
        <apex:commandButton value="Last Page" action="{!last}"/>
    </apex:pageblockButtons>
    
        <apex:tabPanel >
            <apex:tab label="High Revenue">
                <apex:pageblockTable value="{!High_revenue_List}" var="var1">
                    <apex:column value="{!var1.name}"/>
                    <apex:column value="{!var1.industry}"/>
                    <apex:column value="{!var1.type}"/>
                     <apex:column value="{!var1.AnnualRevenue}"/>
                </apex:pageblockTable>
            </apex:tab>
            <apex:tab label="Zero Revenue">
                <apex:pageblockTable value="{!Low_revenue_List}" var="var2">
                     <apex:column value="{!var2.name}"/>
                    <apex:column value="{!var2.industry}"/>
                    <apex:column value="{!var2.type}"/>
                     <apex:column value="{!var2.AnnualRevenue}"/>
                </apex:pageblockTable>         
                
         
            </apex:tab>
        </apex:tabPanel>
    </apex:pageBlock>
 </apex:form>
</apex:page>
Hello Developers,

The apex trigger below is basically a rollup count of the Contact Roles assigned to the Opportuniy. The trigger works great but only executes when I edit and save the Opportunity. I need the trigger to execute as soon as a Contact Role is created and assigned to update the Opportunity fields. Any assistance is greatly appreciated!
 
trigger RollUpContactRole on Opportunity (before update)
{

Map<Id,List<opportunityContactRole>> oppConRole = new Map<Id,List<opportunityContactRole>>();

Map<Id, Opportunity> oppty_con = new Map<Id, Opportunity>();

for (Integer i = 0; i < Trigger.new.size(); i++)
{
        oppty_con.put(Trigger.new[i].id,Trigger.new[i]);      
}

for (OpportunityContactRole oppcntctrle :[select OpportunityId,IsPrimary from OpportunityContactRole where OpportunityContactRole.OpportunityId in :oppty_con.keySet()])
{
    if(!oppConRole.containsKey(oppcntctrle.OpportunityId)){
        List<opportunityContactRole> temp = new List<opportunityContactRole>();
        temp.add(oppcntctrle);
        oppConRole.put(oppcntctrle.OpportunityId,temp);
    }else{
        List<opportunityContactRole> temp1 = new List<opportunityContactRole>();
        temp1 = oppConRole.get(oppcntctrle.OpportunityId);
        temp1.add(oppcntctrle);
        oppConRole.put(oppcntctrle.OpportunityId,temp1);
    }
}

for (Opportunity Oppty : system.trigger.new) 
{
    if(oppConRole.containsKey(Oppty.Id)){
        Oppty.Number_of_Contacts_Roles_Assigned__c = (oppConRole.get(Oppty.Id)).size();
        for(opportunityContactRole ocr : oppConRole.get(Oppty.Id)){
            if(ocr.IsPrimary){
                Oppty.Primary_Contact_Assigned__c =true;
                continue;
            }
        }
    }else{
        Oppty.Number_of_Contacts_Roles_Assigned__c = 0;
        Oppty.Primary_Contact_Assigned__c =false;
    }   
}

}

 
  • February 11, 2017
  • Like
  • 0
Hi all, I seem to be stuck on authoring the class and test classes on the Superbadge Data Integration Specialist. I have authored the ProjectCalloutService plus the test class and HTTPCallouts, but encounter a Null pointer exception error at line 35:1

Anything I should add to the code. I have built the process builder as needed.

Project Callout Service
public class ProjectCalloutService {
    public static Id opportunityId;
    
    @InvocableMethod
    public static void postOpportunityToPMS(List<Id> opportunityIds){
        opportunityId=opportunityIds.get(0);
        Opportunity opp=[Select Id,Name, closeDate,amount,Account.Name FROM Opportunity Where Id =: opportunityId];
        ID jobID = System.enqueueJob(new QueueablePMSCall(opp));
    }    
    
    public class QueueablePMSCall implements system.Queueable,Database.AllowsCallouts
    {
        private String jsonOpp;
        private Opportunity opportunityObject;
        public QueueablePMSCall(Opportunity opp)
        {
            opportunityObject=opp;
            JSONGenerator gen = JSON.createGenerator(true);
            gen.writeStartObject();
            gen.writeStringField('opportunityId', opp.Id);
            gen.writeStringField('opportunityName', opp.Name);
            gen.writeStringField('accountName', opp.account.Name);
            gen.writeDateField('closeDate', opp.closeDate);
            gen.writeNumberField('amount', opp.amount);
            
            gen.writeEndObject();            
            
            jsonOpp= gen.getAsString();
            System.debug('jsonOpp: ' + jsonOpp);
            
        }
        public void execute(QueueableContext context) {
            
            ServiceTokens__c token= ServiceTokens__c.getValues('ProjectServiceToken');
            System.debug(token.Token__c);
            
            // create an HTTPrequest object    
            HttpRequest req = new HttpRequest();
            req.setMethod('POST');
            req.setEndpoint('callout:ProjectService/'+ token.Token__c);
            req.setHeader('Content-Type', 'application/json');
            req.setBody(jsonOpp);    
            
            // create a new HTTP object
            Http http = new Http();
            HTTPResponse res = http.send(req);
            if (res.getStatusCode() != 201) {
                System.debug('Error from ' + req.getEndpoint() + ' : ' +
                             res.getStatusCode() + ' ' + res.getStatus());
                
                Opportunity opportunity1=[Select Id, StageName FROM Opportunity Where Id =: opportunityObject.Id];
                opportunity1.StageName='Resubmit Project';
                update opportunity1;
                
            }
            else {
                Opportunity opportunity2=[Select Id, StageName FROM Opportunity Where Id =: opportunityObject.Id];
                opportunity2.StageName='Submitted Project';
                update opportunity2;
            }      
        }
        
    } 
}
Test Class
@isTest
private class ProjectCalloutServiceTest {
  //Implement mock callout tests here
  public static testMethod void testSuccess(){
      Account acc = new Account(Name='Test Account');
      insert acc;
      Opportunity opp = new Opportunity(Name='Test Opportunity',
                        AccountId=acc.id, CloseDate=System.Today(),
                        Amount=12480.00,
                        Type='New Project',
                        StageName='Qualification');
      insert opp;
      Test.startTest();
      Test.setMock(HttpCalloutMock.class, new ProjectCalloutServiceMock());
      Test.stopTest();
      opp.StageName='Closed Won';
      update opp;
      
  }
  public static testMethod void testFailure(){
      Account acc = new Account(Name='Test Account');
      insert acc;
      Opportunity opp = new Opportunity(Name='Test Opportunity',
                        AccountId=acc.id, CloseDate=System.Today(),
                        Amount=12480.00,
                        Type='New Project',
                        StageNAme='Qualification');
      insert opp;
      Test.startTest();
      Test.setMock(HttpCalloutMock.class, new ProjectCalloutServiceMockFailure());
      Test.stopTest();
      opp.StageName='Closed Won';
      update opp;
  }
}

HTTP Callout Success
global class ProjectCalloutServiceMock implements HttpcalloutMock{
   //Implement http mock callout here
   global HttpResponse respond(Httprequest request){
       HttpResponse response = new Httpresponse();
       String resBody = '[Status=Created, StatusCode=201]';
       response.setHeader('Content-Type','application/json');
       response.setBody(resBody);
       response.setStatusCode(201);
       return response;
   }
}
HTTP Callout Fail
 
//ProjectCalloutServiceMockFailure
global class ProjectCalloutServiceMockFailure implements HttpcalloutMock{
   //Implement http mock callout failure here 
   //Implement http mock callout here
   global HttpResponse respond(Httprequest request){
       HttpResponse response = new Httpresponse();
       String resBody = '[Status=Created, StatusCode=501]';
       response.setBody(resBody);
       response.setStatusCode(501);
       return response;
   }
}


 
Hi,

i am getting below error while completing "Lightning Experience Rollout Specialist Superbadge Step #8"
Challenge Not yet complete... here's what's wrong:
Knowledge must be enabled for the org.
.User-added image


i have alredy enabled knowledge settings..

User-added image

Thank you.
I am getting the following error:

Challenge Not yet complete... here's what's wrong: 
Lightning Knowledge hasn't been turned on.

When Lightning Knowledge is clearly turned on.  All users (myself and the two users for challenge) have the permission set.  My user and Johon Wiseman have the Knowledge User box checked on User Record.  It's on, but system isn't seeing it for some reason.

User-added image
Hi, we are hitting our API request limit and I would like to find out what apps are consuming requests.

I've looked into the Admin report with requests of last 7 days and the event log file browser application. However, in both cases I'm not able to find what I need.

How can I find out which apps are using how many API requests? Thanks a lot.
 
Team,

I am looking for some info into sending records to an external API everytime an Account is created or updated.
It will not be a Batch Job, but instead a callout everytime account information changes.
Is it possible to do it from the salesforce layout itself,  without having to write a custom VF page for triggering the callout ?
( The reason I mentioned VF page route, because that is what I know).
I have already gone through the developer guide , so please don't reference that.
I am not looking for code , but the framework/algorithm to do it.

Any help will be appreicated.
Thanks!
 
Hello,

I have a requirement where I need to access Campaign Influence records in the Opportunity related list by SOQL query. Basically, I need to access it because I have custom object looking up to CAMPAIGN. And I want to show all opportunities in that custom object related list "Opportunities" upon on adding the Campaign in the custom object.

Thanks,
GR
I have a line of code like this:

Map<Id,Account> contactMap = new Map<Id,Account>();

I want to keep this code, but I also want two more field values, so that values for Account ID, Title, and AssistantName are collected on a Contact record. Any tips on how to do this? I'm fairly new to Apex coding. Thank you!
Hi,

I have a mobile application doing some analytics and showing the metrics with enterpise apps. Now I have a requirement to include SalesForce data as well. I don't want to use Connected App mechanism as it limits the usage only some particular account. My app is quite generic and given the SF credentials (login & passowrd) it should work!

Thanks in advance & Regards,
Kalyan.
 
public class CreateInvoice{
    
    public CreateInvoice(){
        
        List<Training__c> trainingList = new List<Training__c>();
        List<Facturatie__c> facturatieList = new List<Facturatie__c>();
        
        try {
        trainingList = [SELECT id , NAME, Startdatum__c,factuur_bedrijf__c,
                          (SELECT Cursist_Prijs__c, Training__c, Cursist__c,CreatedDate,Prijs_training__c,
                           korting__c,Id 
                           FROM Trainingen_Volgen__r ) 
                       FROM  Training__c 
                       WHERE id NOT IN (SELECT  Training__c FROM Facturatie__c)];
        }catch (Exception e) {
            System.debug('The following exception has occurred' + e.getMessage() +
                         'At line number :' + e.getLineNumber() + 'Error' +
                         e.getStackTraceString());
        }              
        if(!trainingList.IsEmpty()){
            
            for(Training__c trainingRecord : trainingList){
                
                if(!trainingRecord.Trainingen_Volgen__r.IsEmpty()){
                    
                    for(Cursist__c cursistRecord : trainingRecord.Trainingen_Volgen__r){
                        
                        Facturatie__c facturatieRecord = checkDate(cursistRecord,trainingRecord);
                        facturatieList.add(facturatieRecord);
                    }
                }   
            }

            if(!facturatieList.IsEmpty()){  
               try {
                   insert facturatieList;
                }catch (Exception e) {
                    System.debug('The following exception has occurred' + e.getMessage() +
                                 'At line number :' + e.getLineNumber() + 'Error' +
                                 e.getStackTraceString());
                }   
               
            }
        }   
    }
    
    public Facturatie__c checkDate(Cursist__c cursistRecord,Training__c trainingRecord){
        
        if(cursistRecord != null && trainingRecord != null){
            Date todaysDate = system.today();
            
            if( todaysDate.addDays(-21) >= trainingRecord.Startdatum__c 
                && todaysDate >= cursistRecord.CreatedDate 
                && todaysDate.addDays(-1) >= trainingRecord.Startdatum__c){
                
                Facturatie__c facturatieRecord = new Facturatie__c();
                
                facturatieRecord.Training__c = trainingRecord.Id;   
                facturatieRecord.Factuur_Datum__c = todaysDate;  
                facturatieRecord.Verval_datum__c = todaysDate.addDays(30);
                
                if(cursistRecord.Prijs_training__c != null &&  cursistRecord.korting__c != null){
                    facturatieRecord.Factuur_Bedrag__c = cursistRecord.Prijs_training__c - cursistRecord.korting__c;
                }else if(cursistRecord.Prijs_training__c != null && cursistRecord.korting__c == null){
                    facturatieRecord.Factuur_Bedrag__c = cursistRecord.Prijs_training__c;
                }else if(cursistRecord.Prijs_training__c == null && cursistRecord.korting__c != null){
                    facturatieRecord.Factuur_Bedrag__c = cursistRecord.korting__c ;
                }
                
                facturatieRecord.Korting__c =  cursistRecord.korting__c;
                facturatieRecord.cursist_prijs__c= cursistRecord.Cursist_Prijs__c ;
                facturatieRecord.Contactpersoon__c = cursistRecord.Cursist__c;
                facturatieRecord.Account__c = trainingRecord.factuur_bedrijf__c; 
                
                return facturatieRecord;
            }
        }
        
        return null;
    }
}
 
@isTest
public class CreateInvoiceTestClass{
    
    // Creating Test Data
   @isTest public static void testData(){
    
        Account account = new Account(Name = 'TestAccount1');  
        insert account;
        
        List<Training__c> trainingList = new List<Training__c>();
        for(integer counter=0;counter<20;counter++){
            
            Training__c trainingRecord = new Training__c();
            trainingRecord.name = 'TestRecord'+counter;
            trainingRecord.Startdatum__c = System.today().addDays(+2);
            trainingRecord.factuur_bedrijf__c = account.Id;
            trainingList.add(trainingRecord);
        }
        insert trainingList;
        
         List<Facturatie__c> facturatieList = new List<Facturatie__c>();
        for(integer counter=0;counter<20;counter++){
            
            Facturatie__c facturatieRecord = new Facturatie__c();
            facturatieRecord.name = 'TestRecord'+counter;
            facturatieRecord.Factuur_Bedrag__c = 1000;
            facturatieRecord.Training__c = trainingList[counter].Id;
            facturatieList.add(facturatieRecord);
        }

       for(integer counter=0;counter<20;counter++){
            
            Facturatie__c facturatieRecord = new Facturatie__c();
            facturatieRecord.name = 'TestRecord2'+counter;
            facturatieRecord.Factuur_Bedrag__c = 1000;
            facturatieRecord.Training__c = trainingList[counter].Id;
            facturatieList.add(facturatieRecord);
        }
  
       insert facturatieList;

       
        List<Cursist__c> cursistList = new List<Cursist__c>();
        for(integer counter=0;counter<20;counter++){
            
            Cursist__c cursistRecord = new Cursist__c();           
            cursistRecord.Training__c = trainingList[counter].Id;
            cursistRecord.Prijs_training__c = 10;
            cursistRecord.korting__c = 10;
            cursistRecord.CreatedDate = System.today();
            cursistList.add(cursistRecord);
        }
        insert cursistList;
       
       system.debug(facturatieList[0].Account__c);
       Test.StartTEst();
	   CreateInvoice createInv = new CreateInvoice();
	   Test.stopTest();
      
       System.assertEquals(facturatieList[0].Account__c,null);
       
    }
   
}

User-added image
Hi all,

I have written the test class for the standard controller extention. While I test run the test class the methods are failed. Below is my test class .

@istest
public class gdaControllerExtension_test {  
static testMethod void testreparentMethod()     {    
 GFrm__c gform = [SELECT ID FROM GFrm__c LIMIT 1];     ApexPages.StandardController stdController = new ApexPages.StandardController(gfrm);     gdaControllerExtension gdcon=new gdaControllerExtension(stdController);     
    gdcon.gfrm.SelectProgram__c='MA';
 gdcon.mfarten();   
}   
static testMethod void testparentreAddresMethod()     {     
GFrm__c gform = [SELECT ID FROM GFrm__c LIMIT 1];     ApexPages.StandardController stdController = new ApexPages.StandardController(gfrm);     gdaControllerExtension gdcon=new gdaControllerExtension(stdController);           
    gdcon.gfrm.SelectProgram__c='AED';
  gdcon.mfarten();   
}       
static testMethod void testparentresetAddressMethod()     {     
GFrm__c gform = [SELECT ID FROM GFrm__c LIMIT 1];     ApexPages.StandardController stdController = new ApexPages.StandardController(gfrm);     gdaControllerExtension gdcon=new gdaControllerExtension(stdController);     
     gdcon.gform.SelectProgram__c='Re-enroll';
 gdcon.mfarten();
  }
}


Can anyone help me over here.

Thanks in advance.

Regards,
mac.
I am experiencing an error when attempting to complete this challenge:

Use Salesforce Connect to link an External Object with Salesforce Users

on this page in the Trailhead training:
https://trailhead.salesforce.com/trails/force_com_dev_intermediate/modules/lightning_connect/units/lightning_connect_integrate

Here is the error message I am receiving:
Challenge Not yet complete... here's what's wrong:
 The User standard object does not have a custom field with the API name 'Phone_UUID__c'

In researching this, I came up with a possible solution posted by Dutta Sourav as follows:

Go to Setup > Manage Users > Users.

Click “Edit” for just one of your users.

Put “0000123442” in the Phone UUID field under the Additional Information heading.

Click Save.


Unfortuantely, search as I may, I cannot find this "Additional Information" heading on the UUID field.

Can anyone help me?
Thanks,
Ryan
We installed java 1.8 on the server but are receiving the following error:

Receiving error:  Windows cannot find \bin\java

User-added image

I am not sure how to test an async callout and have not had any luck looking at other posts. I am new to apex so i would appreciate any help, my class is below split into 2 methods due to a conflicting trigger. I need the future due to the 10 second cpu limitation and i need to update 2.5k rows of data based on the json it works when i run it pn my test site but i cant get the test coverage.

public class JSONPullData {
   public static List<Contract> con2;
    public static HttpResponse response;
    
    // @future(callout=true)
    public static HttpResponse parseJSONResponse() {        

            update con2;
        
        return response;
    }
        
        
     
    @future(callout=true)
    public static void processData(){
                //Setup the connection to the json to pull in
        JsonUtil Jutil = new JsonUtil();
         Http httpProtocol = new Http();
        // Create HTTP request to send.
        HttpRequest request = new HttpRequest();
        // Set the endpoint URL.
        request.setEndPoint('url');
        // Set the HTTP verb to GET.
        request.setMethod('GET');
        // Send the HTTP request and get the response.
        // The response is in JSON format.
       response = httpProtocol.send(request);
       
        if(response.getStatusCode() == 200){
            //System.debug(response.getBody());
            
            //deserialize the json 
            List<Object> eqt = (List<Object>) JSON.deserializeUntyped(response.getBody());
            //add the street address to the set the set cannot have duplicates so the street must be unique
            Map<string,string> st = new Map<string,string>();
            Map<string,Double> stRent = new Map<string,Double>();
            for (Object o : eqt){
                Map<String,Object> mapobj = (Map<string,Object>)o;
                
                st.put((String)mapobj.get('Street'),(String)mapobj.get('Date'));
                stRent.put((String)mapobj.get('Street'),(Double)mapobj.get('Rent'));
                
            }
            //find all the space names that match the street in the set
            // System.debug(st);
            Map<ID,Contract> con = new Map<ID,Contract>([Select id, Space__r.Name,Current_Rental_Rate__c, Space__c from Contract where Space__r.Name IN :st.keySet() and Active__c = TRUE]);
            
            //create a list of spaces that are connected to the leases
            List<Space__c> s = [Select id,Name,Active_Contract__c from Space__c where Active_Contract__c IN :con.keySet()];
            //System.debug(s);
            //create maps to locate the data
            Map<id, Double> holdLease = new  Map<id, Double>();
            Map<id, Date> holdDate = new  Map<id, Date>();
            for(Space__c c: s){
                //for (Object o : eqt){
                // Map<string,Object> mapobj = (Map<string,Object>)o;
                //  if(c.Name == (String)mapobj.get('Street')){
                //    System.debug((String)mapobj.get('Renewal Date'));
                //map the rent and renewal date
                System.debug(c.Name);
 
                Date d = date.parse(st.get(c.Name));
                
               
                holdDate.put(c.Active_Contract__c, d);
                holdLease.put(c.Active_Contract__c, stRent.get(c.Name));
                
                
            }
            
            //}    
            
            con2 = [Select id, Space__r.Name,Name,Current_Rental_Rate__c, Space__c from Contract where id in :holdLease.keySet()];
            // System.debug(con2);
            // 
            //set up email
            Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
            message.setSenderDisplayName('Salesforce Support');
            message.toAddresses = new String[] { 'email@email.com' };
                message.optOutPolicy = 'FILTER';
            message.subject = 'Log Updated Rent for lease rr';
            String mess = '';
            mess = mess + 'Lease ID - Lease Name - Space Name - Rent' + '</br></br>';
            for(Contract c: con2){
                if(holdLease.containsKey(c.id)){
                    //modify the values
                    mess = mess + c.id + ' - ' + c.Name + ' - ' + c.Space__r.Name + ' - ' + c.Current_Rental_Rate__c  + '</br>';
                    c.Current_Rental_Rate__c = holdLease.get(c.id);
                    c.Renewal_Date__c = holdDate.get(c.id);
                }
                
                
            }
            
            message.setHtmlBody(mess);
            Messaging.SingleEmailMessage[] messages =  new List<Messaging.SingleEmailMessage> {message};
                Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
            JSONPullData.parseJSONResponse();
    }
    
}
}


@isTest
private class JsonPullDataCallout_Test {
    @isTest static void testCallout() {
        // Set mock callout class 
        Test.setMock(HttpCalloutMock.class, new JsonPullData_Test());
        
        // Call method to test.
        // This causes a fake response to be sent
        // from the class that implements HttpCalloutMock.
        Test.startTest(); 
        JSONPullData.processData();
        Test.stopTest();
        HttpResponse res = JSONPullData.response;
        // Verify response received contains fake values
        String contentType = res.getHeader('Content-Type');
        System.assert(contentType == 'application/json');
        String actualValue = res.getBody();
        String expectedValue = '[{"Street":"123 Test Road","Rent":1356.95,"Date":"1/9/2017"}]';
        System.assertEquals(actualValue, expectedValue);
        System.assertEquals(200, res.getStatusCode());
        
        
    }
}


@isTest
global class JsonPullData_Test implements HttpCalloutMock {
    // Implement this interface method
    public static HTTPResponse res;
    global HTTPResponse respond(HTTPRequest req) {
        // Optionally, only send a mock response for a specific endpoint
        // and method.
        System.assertEquals('url', req.getEndpoint());
      
        System.assertEquals('GET', req.getMethod());
        
        // Create a fake response
        HttpResponse res = new HttpResponse();
        res.setHeader('Content-Type', 'application/json');
        res.setBody('[{"Street":"123 Test Road","Rent":1356.95,"Date":"1/9/2017"}]');
        res.setStatusCode(200);
        return res;
    }

    }
I am working to integrate FormAssembly forms in Salesforce and need assistance with writing the test class for the code. I would think that this would be something I could easily find since this seems like a common use case, but I am not able to find anything. Has anyone written a test class associated with FormAssembly integration in Salesforce? Essentially, the code is working in the sandbox. I am just trying to display the form using a visualforce page. Here is the code. I used the instructions written by FormAssembly, but those did not include how to create the test class.

Controller:

public class SuggestionBoxController{

    public HTTPResponse res {get; set;}
    public String resBody {get; set;}
    public String endpoint {get; set;}

    public SuggestionBoxController() {
        PageReference pageRef = ApexPages.currentPage();

        HttpRequest req = new HttpRequest();
        req.setMethod('GET');

        if(pageRef.getParameters().get('tfa_next') == null){
          //Replace 'FORM_ID' with your form's ID number
          endpoint = 'https://app.formassembly.com/rest/forms/view/4604281';
        }else{
          endpoint = 'https://app.formassembly.com/rest' + pageRef.getParameters().get('tfa_next');
        }
        req.setEndpoint(endpoint);

        Http http = new Http();
        try {
                //Execute web service call here
                res = http.send(req);
                resBody = res.getBody();
        } catch(System.CalloutException e) {
            //Exception handling goes here....
            System.debug(e);
        }
    }
}

Visualforce Page:

<apex:page controller="SuggestionBoxController">
<apex:outputText value="{!resBody}" escape="false" />
</apex:page>
I am on the last module of the Build a Discount Calculator trail. I have verified the first 4 steps and received the 50 points (everything was configured correctly). Now, when I try to verify my last step I am getting the following error:

Challenge Not yet complete... here's what's wrong: 
The 'Calculate Discount' custom button doesn't exist or isn't properly configured. Check the instructions.

I've verfied the creation of the button, it's on the correct page layout and I've tested the button- it gives me the correct discount percentage and discounted amount.

Any other ideas on what I should check? I'm at a loss.