• Sam Ward
  • NEWBIE
  • 85 Points
  • Member since 2016

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 14
    Replies
I have 2 objects (Account and case), where Case record will be created from an external source which passes account number as a input, Based on the account number I need to capture Account ID and assocciate the record. Can you please suggest how to go forward for this requirement?
Hi,

I'm wanting to remove currency, ID, and recordtypeid from my JSON file but I can't seem to find a way to remove them from the JSON file, Can someone advise where / What I need to be looking at to. Please see the code below.
 
public class JsonGenDispositionData {
    
    public String jsonString {set;get;}
    
    public static void gatherDispositionData(){
            
        List<stage_tracker__c> dispositionDataToSend = [SELECT Distribution_id__c,contact_status__c FROM Stage_Tracker__c WHERE Distribution_id__c != null LIMIT 3];
        List<Stage_tracker__c> payload = new list <Stage_Tracker__c>();
        
        // system.debug('Stage Trackers' + dispositionDataToSend);
        
        If(dispositionDataToSend.isempty()==false){
            JSONGenerator gen = JSON.createGenerator(true);
            for(Stage_Tracker__c ST : dispositionDataToSend){
                gen.writeStartArray();
                gen.writeStartObject();
                gen.writeStringField('DISTRIBUTION_ID', ST.Distribution_Id__c);
                gen.writeBooleanField('CONTACT_STATUS', ST.contact_status__c);
                gen.writeEndObject();
                gen.writeEndArray();
                payload.add(ST); 
            }
        }
        
        string jsonString = JSON.serialize(payload);
        system.debug(jsonString);
    }
    
}

My currnet output:
 
[{"attributes":{"type":"Stage_Tracker__c","url":"/services/data/v53.0/sobjects/Stage_Tracker__c/a5i3z000000UKNZAA4"},
"Distribution_Id__c":"8056fec2-b009-2cde-2d98-5f9ad4",
"contact_status__c":true,
"Id":"a5i3z000000UKNZAA4",
"RecordTypeId":"0123z000000gHwCAAU",
"CurrencyIsoCode":"GBP"}]
 I dont need the last 3 lines, (Id / RecordTypeId / CurrencyIsoCode)

How can I remove them.

Also any general code improvments would be welcomed.

Thanks
​​​​​​​
I'm new to apex code and I've got everything working its just the test class i'm struggling on. 

Here is my Apex Class
public class ramassistAPI {

@future  (callout=true)
    public static void updateopp() {
    
        DVLA_Lookup_Opportunity__c DVLA = [SELECT id
                                          FROM
                                          DVLA_Lookup_Opportunity__c
                                          WHERE Stage__c = 'Closed Won' AND SentToAPI__c = 'Pending'];
        DVLA.SentToAPI__c = 'Sent';
        update DVLA;
    }
}

My test class is:
@isTest
private class RamassistApiTest {
    static testMethod void TestOppUpdating() {
        
        Account acct = new Account(Name='Test');     
        insert acct;
        
        Contact con = new Contact(LastName = 'Bloggs',FirstName = 'Joe',Phone = '01234567890',Email = 'test@test.com',AccountId = acct.Id);
        insert con;
        
        DVLA_Lookup_Opportunity__c dvlaOpp = new DVLA_Lookup_Opportunity__c(Account__c = acct.Id, Stage__c = 'Closed Won',Close_Date__c = System.today(),SentToAPI__c = 'Pending',Contact__c = con.Id);            
        insert dvlaOpp;
        
        dvlaOpp = [SELECT Id, SentToAPI__c FROM DVLA_Lookup_Opportunity__c WHERE Stage__c = 'Closed Won' AND SentToAPI__c = 'Sent' AND Id =: dvlaopp.Id];         
        dvlaOpp.SentToAPI__c = 'Sent';
        update dvlaOpp;   	
               
        // Do the test
        test.startTest();
        System.assertEquals('Sent', dvlaOpp.SentToAPI__c);
        test.stopTest();
    }     
}

Can anyone give me some advice to where i might be going wrong? 

Thanks
 
Hi,

So I have the below code and I know it works okay 
 
global class MarketingClicks implements Schedulable {
    global void execute(SchedulableContext ctx) {
        List<Lead> Leadlist = [SELECT Id, Campaign_Name__c FROM Lead WHERE Campaign_Name__c != ''];

  if(!LeadList.isEmpty()){
        for(Lead L : LeadList)
        {        
            //Create Marketing Click
            L.Link_Type__c = 'TEST';
            Pardot_Campaign__c PC = new Pardot_Campaign__c();
            PC.Lead__c = L.Id;
            PC.Name = L.Campaign_Name__c;
            insert PC;
            L.Campaign_Name__c= '';
            Update L;
            }
        }
        System.debug(Leadlist);
    }
    
}

I have also added in 4 schedules which trigger this: 
 
System.schedule('Marketing Clicks Job 1', '0 0 * * * ?', new MarketingClicks ());
System.schedule('Marketing Clicks Job 2', '0 15 * * * ?', new MarketingClicks ());
System.schedule('Marketing Clicks Job 3', '0 30 * * * ?', new MarketingClicks ());
System.schedule('Marketing Clicks Job 4', '0 45 * * * ?', new MarketingClicks ());
Again this works fine from what i'm seeing. 

I've then tried to write a test class by following a video and changing the fields that I need instead of what the video was using and it doesn't work can someone help please? 

Test Class: 
@isTest
Public Class MarketingClicksTest
{
  @testSetup
    static void setup()
    {
        List<Lead> Leadlist = new List<Lead>();
        for(Integer i=1;i<=10;i++)
        {
         Lead Id = new Lead(Company='Test',Lastname='sam',Status='Open',UK_Canada__c='UK',Phone='000000',Online_Offline__c='Offline',Enquiry_Source__c='Cold Call',Method__c='N/A',Position__c='UNASSIGNED',Industry_Sector__c='Miscellaneous',Campaign_Name__c='Test');
        }
        insert LeadList;
    }
    
    static testmethod void testMarketingClicksScheduleJob()
    {
        string sch='0 5 12 10 2 ?';
        Test.startTest();
        string jobId=system.schedule('scheduleApexTest',sch,new MarketingClicks());
        List<Lead> LeadList=[SELECT Id, Campaign_Name__c FROM Lead WHERE Campaign_Name__c != ''];
        system.assertEquals(10, Leadlist.size());
        Test.stopTest();
    }
}


Thanks in advance
I have written the above code but I'm unsure how you would write a test class can someone point me to a video or any documention which will help me learn this please? 

I have attached my code incase its a really simple test class to write. 
global class MarketingClicks implements Schedulable {
    global void execute(SchedulableContext ctx) {
        List<Lead> Leadlist = [SELECT Id, Campaign_Name__c FROM Lead WHERE Link_Type__c != ''];

        for(Lead L : LeadList)
        {        
            //Create Marketing Click
            L.Link_Type__c = 'TEST';
            Pardot_Campaign__c PC = new Pardot_Campaign__c();
            PC.Lead__c = L.Id;
            PC.Name = L.Campaign_Name__c;
            insert PC;
            L.Campaign_Name__c= '';
            Update L;
            }
        System.debug(Leadlist);
    }
    
}

Thanks in advance
Hi, 

New to Apex so I dont fully understand how it all works however I have got the following peice of code working: 
 
global class batchExample implements Database.Batchable<sObject> {
    
    
    global Database.QueryLocator start(Database.BatchableContext BC) {
        // collect the batches of records or objects to be passed to execute
        
        String query = 'SELECT Id,Link_Type__c FROM Lead';
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC, List<Lead> LeadList) {
       
        // process each batch of records

        
        for(Lead L : LeadList)
        {        
            // Update the Account Name 
            //L.Link_Type__c = 'TEST';
            Pardot_Campaign__c PC = new Pardot_Campaign__c();
            PC.Lead__c = L.Id;
            insert PC;
            
            }
            
        try {
            // Update the Account Record
            update LeadList;
        
        } catch(Exception e) {
            System.debug(e);
        }
        
    }   
    
    global void finish(Database.BatchableContext BC) {
        // execute any post-processing operations
  }
}

That works and creates the additional records however I want it based on if a field has changed since it last checked it. 

Field name: Pardot Campaign 

This updates with a value if someone has clicked on a link from an email so I only want the leads that have changed prior to the scheduled apex running if that makes sense. I've been searching on how to look for a value change but couldn't find anything. 

Thanks 
public class SurveyRedirect {

    public String ObjectId {get;set;}
    public String Code {get;set;}
    public String PageR {get;set;}
    
    public SurveyRedirect () {
        ObjectId = ApexPages.currentPage().getParameters().get('id');
        Code = ApexPages.currentPage().getParameters().get('Code');
       PageR = ApexPages.currentPage().getParameters().get('PageR');
        system.debug(ObjectId);
    }
    public PageReference onLoad() {
        List<Lead> Lead = [SELECT Id, Campaign_Name__c FROM Lead WHERE id=:ObjectId LIMIT 1];
        if(!Lead.IsEmpty()){
        Lead[0].Campaign_Name__c = Code;
            UPDATE Lead;
            }
           PageReference pr = new PageReference(PageR);
              pr.setRedirect(true);
              return pr;
        }
    }
I'm new to Apex so I dont know how to write a test class any help on how to write them would be much appericated.

Thanks
Hi,

I have the below code but for some reason it will not find the lead to update.

I'm making sure my URL has ?id=00Q3H000002GWoIc but it just seems to ignore this I think its because it can't find it. Then does the page redirect as I want it to. 
 
public with sharing class SurveyRedirect {

    public String ObjectId {get;set;}
    public String ResponseCode {get;set;}
    public SurveyRedirect () {
        ObjectId = ApexPages.currentPage().getParameters().get('ObjectId');
        ResponseCode = ApexPages.currentPage().getParameters().get('ResponseCode');
    }
    public PageReference onLoad() {
        List<Lead> Lead = [SELECT Id, Cars__c FROM Lead WHERE Id=:ObjectId LIMIT 1];
        if(!Lead.IsEmpty()){
        Lead[0].Cars__c = True;
            UPDATE Lead;
            }
           PageReference pr = new PageReference('http://www.google.com');
              pr.setRedirect(true);
              return pr;
        }
    }

Any feedback or direction where to look would be greatly appericated. 

Thanks
Here is my Class
global class AdditionalUnitRequest {  
    
    string RecId = apexpages.currentpage().getparameters().get('id');
    
    public string fieldvalue {get;set;}
    public decimal yourNoUnits {get;set;}
    public Opportunity opp {get;set;}
    
    // This gets the finance details related to RecId
         
    list <Finance_Details__c> FinanceDetails;
     global List <Finance_Details__c> getFinanceDetails(){
         FinanceDetails = [SELECT id,Billing_Cycle__c,Account_Name__r.Name,Term__c,Price_Per_Month__c,Contact__r.Name
            FROM Finance_Details__c WHERE Account_Name__c = :RecId AND RecordType.Name = :'Last Order Details' Limit 1];
     return FinanceDetails;
     }
    
    // This is for the picklist options
    
	public string selectedname{get;set;}
    
            
    global list <selectOption> getselectednamefields(){
      list<selectOption> lstnamesel = new list <selectOption>();
            lstnamesel.add(new selectOption('','-- None --'));
            for (Contact con: [SELECT id,name,email FROM Contact WHERE Account.id =: '001D0000026gSLH' AND Allowed_to_Sign__c =: TRUE])
            lstnamesel.add(new selectOption(con.id,con.name));
            return lstnamesel;
        }
    

    // This creates the opportunity with details
    
    public void passValueToController(){
        fieldvalue = selectedname;
        
        string RecId = apexpages.currentpage().getparameters().get('id');        
        string RecType = '012D0000000Bamx';
        string OppType = 'Additional Units';
        string Stage = '02 - Pending';
        string SubStage = 'Finance Proposed';
        string TM = '005D0000001ynPu';
        string OppCur = 'CAD - Canadian Dollar';
        string HowsFunded = 'external Lease (Canada)';
    	String Contact = fieldvalue;
        
        Contact c = [SELECT id, name, email, Account.Name FROM Contact WHERE contact.id =: fieldvalue];
       
        string CompanyName = c.Account.Name;
  
        // Assign values to opp
        opp = New Opportunity();
        opp.Name = CompanyName + ' 1';
        opp.AccountId = RecId;
        opp.Main_Contact_Name__c = Contact;
        opp.StageName = Stage;
        opp.Type = OppType;
        opp.Sub_Stage__c = SubStage;
        opp.CloseDate = system.today() + 31;
        opp.User__c = id.valueOf(TM);
    //opp.TotalOpportunityQuantity = ; ****** I'm wanting to update this field from the VF Page *********
        opp.CurrencyIsoCode = 'CAD';
        opp.How_is_the_order_funded__c = HowsFunded;
        
        
        //Create Opp
        insert opp;
    } 

}

Here is my VF Page: 
 
<apex:page showHeader="false" sidebar="false" Controller="AdditionalUnitRequest" >

<style>
</style>

    
    <apex:dataTable value="{!FinanceDetails}" var="fd" width="700px">
        <apex:column headerValue="Billing Cycle" width="12%">
            <apex:outputText value="{!fd.Billing_Cycle__c}"/> 
        </apex:column>
        <apex:column headerValue="Account Name" width="12%">
            <apex:outputText value="{!fd.Account_Name__r.Name}"/> 
        </apex:column>
        <apex:column headerValue="Term" width="12%">
            <apex:outputText value="{!fd.Term__c}"/> 
        </apex:column>
        <apex:column headerValue="Price Per Month" width="12%">
            <apex:outputText value="{!fd.Price_Per_Month__c}"/> 
        </apex:column>
        <apex:column headerValue="Contact" width="12%">
            <apex:outputText value="{!fd.Contact__r.Name}"/>
        </apex:column>
    
    </apex:dataTable>

<apex:form >
    <span> Contacts: </span>
        <apex:selectList size="1" value="{!selectedname}" onclick="" >
            <apex:selectOptions value="{!selectednamefields}"/>
           <!--   <apex:actionSupport action="{!passValueToController}" reRender="values" event="onchange"/>   -->
        </apex:selectList>
       <apex:inputField value="{!Opp.TotalOpportunityQuantity}" >
       </apex:inputField>
       <!-- <apex:outputText value="{!fieldValue}" label="You have selected:" id="values"/> -->
        <apex:commandButton status="sending" styleClass="buttons" action="{!passValueToController}" title="Order Additionals" value="Order Additionals" oncomplete="Submitted()">
        </apex:commandButton> 
        
</apex:form>



    
</apex:page>

It is the total Opportunity Quantity I'm trying to to map into the the class, I have tried various things but I can't seem to figure it out. I'm sure its something really obvious i'm missing any help would be appreciated. Thanks in advance. 
Hi, 

I have the below code but I just keep getting a syntax error, I want to display 1 flow if the users country is united kingdom and if not it defaults to a different flow, Here is my code below: 

<apex:page standardController="Vacation_Request__c">

    <apex:sectionheader title="Holiday Request - {!$User.FirstName} {!$User.LastName}"></apex:sectionheader>

    {!IF(({!$User.Country} == 'United Kingdom'),
    

    <flow:interview name="Vacation_Request" finishLocation="{!URLFOR('/home/home.jsp')}">
        <apex:param name="var_UserId" value="{!$User.Id}"></apex:param>
        <apex:param name="var_Username" value="{!$User.FirstName} {!$User.LastName}"></apex:param>
    </flow:interview>,
    
     <flow:interview name="Canada_Vaction_Request" finishLocation="{!URLFOR('/home/home.jsp')}">
        <apex:param name="var_UserId" value="{!$User.Id}"></apex:param>
        <apex:param name="var_Username" value="{!$User.FirstName} {!$User.LastName}"></apex:param>
    </flow:interview>
     
     )}
     
</apex:page>


any help would be much appericated. 

Thanks 
Hi, 

I am just wanting to be able to pass the current pages Name to my visualforce page, My visualforce page has a customer controller and is displaying a datatable, I can post both if there are any amendments to the code which might be needed. 

My end goal is to have a button on an account which someone can click and download any (Custom Object) Service Bookings meeting a critea matching the Account ID so that I can create a Proforma Invoice as a PDF. 

Thanks in advance. 
I am new to javascript but having some problems getting it to execute and update fields, Please see below a screen shot of what I have so far, I think its something to do with the Stock.Name rather than an ID but not sure. If anyone can point me in the right direction that would be great. 

User-added image

Thanks in advance
Hey, So I've been all over the forums and cannot seem to find the solution for this or where I am going. If anyone could shed any light on this it would be much appreciated.

What am trying to achieve: Validation of Picklist which cannot be (Blank) Here is what I've got so far:

AND ( 
$Label.Validation_Switch = "ON", 
Cancelled__c = True, 
(Case_ID__r.UK_Canada__c)= "UK", 
ISBLANK(Reason_for_Cancellation__c), 
TEXT(Reason_for_Job_Cancellations__c) <> "None", 
TEXT(Drill_Down_on_cancelled_reason__c) <> "None")​

Okay so the top couple of lines run and work absolutly fine but then when I place those 2 extra requirements in it accepts the code but validate anything. 

I've tried a few different things this is the last thing I tried and where I am currently stuck!

Any help would be massive on this.
Thanks 

I have 2 objects (Account and case), where Case record will be created from an external source which passes account number as a input, Based on the account number I need to capture Account ID and assocciate the record. Can you please suggest how to go forward for this requirement?
I'm new to apex code and I've got everything working its just the test class i'm struggling on. 

Here is my Apex Class
public class ramassistAPI {

@future  (callout=true)
    public static void updateopp() {
    
        DVLA_Lookup_Opportunity__c DVLA = [SELECT id
                                          FROM
                                          DVLA_Lookup_Opportunity__c
                                          WHERE Stage__c = 'Closed Won' AND SentToAPI__c = 'Pending'];
        DVLA.SentToAPI__c = 'Sent';
        update DVLA;
    }
}

My test class is:
@isTest
private class RamassistApiTest {
    static testMethod void TestOppUpdating() {
        
        Account acct = new Account(Name='Test');     
        insert acct;
        
        Contact con = new Contact(LastName = 'Bloggs',FirstName = 'Joe',Phone = '01234567890',Email = 'test@test.com',AccountId = acct.Id);
        insert con;
        
        DVLA_Lookup_Opportunity__c dvlaOpp = new DVLA_Lookup_Opportunity__c(Account__c = acct.Id, Stage__c = 'Closed Won',Close_Date__c = System.today(),SentToAPI__c = 'Pending',Contact__c = con.Id);            
        insert dvlaOpp;
        
        dvlaOpp = [SELECT Id, SentToAPI__c FROM DVLA_Lookup_Opportunity__c WHERE Stage__c = 'Closed Won' AND SentToAPI__c = 'Sent' AND Id =: dvlaopp.Id];         
        dvlaOpp.SentToAPI__c = 'Sent';
        update dvlaOpp;   	
               
        // Do the test
        test.startTest();
        System.assertEquals('Sent', dvlaOpp.SentToAPI__c);
        test.stopTest();
    }     
}

Can anyone give me some advice to where i might be going wrong? 

Thanks
 
I have written the above code but I'm unsure how you would write a test class can someone point me to a video or any documention which will help me learn this please? 

I have attached my code incase its a really simple test class to write. 
global class MarketingClicks implements Schedulable {
    global void execute(SchedulableContext ctx) {
        List<Lead> Leadlist = [SELECT Id, Campaign_Name__c FROM Lead WHERE Link_Type__c != ''];

        for(Lead L : LeadList)
        {        
            //Create Marketing Click
            L.Link_Type__c = 'TEST';
            Pardot_Campaign__c PC = new Pardot_Campaign__c();
            PC.Lead__c = L.Id;
            PC.Name = L.Campaign_Name__c;
            insert PC;
            L.Campaign_Name__c= '';
            Update L;
            }
        System.debug(Leadlist);
    }
    
}

Thanks in advance
Hi,

I have the below code but for some reason it will not find the lead to update.

I'm making sure my URL has ?id=00Q3H000002GWoIc but it just seems to ignore this I think its because it can't find it. Then does the page redirect as I want it to. 
 
public with sharing class SurveyRedirect {

    public String ObjectId {get;set;}
    public String ResponseCode {get;set;}
    public SurveyRedirect () {
        ObjectId = ApexPages.currentPage().getParameters().get('ObjectId');
        ResponseCode = ApexPages.currentPage().getParameters().get('ResponseCode');
    }
    public PageReference onLoad() {
        List<Lead> Lead = [SELECT Id, Cars__c FROM Lead WHERE Id=:ObjectId LIMIT 1];
        if(!Lead.IsEmpty()){
        Lead[0].Cars__c = True;
            UPDATE Lead;
            }
           PageReference pr = new PageReference('http://www.google.com');
              pr.setRedirect(true);
              return pr;
        }
    }

Any feedback or direction where to look would be greatly appericated. 

Thanks
Hi, 

I have the below code but I just keep getting a syntax error, I want to display 1 flow if the users country is united kingdom and if not it defaults to a different flow, Here is my code below: 

<apex:page standardController="Vacation_Request__c">

    <apex:sectionheader title="Holiday Request - {!$User.FirstName} {!$User.LastName}"></apex:sectionheader>

    {!IF(({!$User.Country} == 'United Kingdom'),
    

    <flow:interview name="Vacation_Request" finishLocation="{!URLFOR('/home/home.jsp')}">
        <apex:param name="var_UserId" value="{!$User.Id}"></apex:param>
        <apex:param name="var_Username" value="{!$User.FirstName} {!$User.LastName}"></apex:param>
    </flow:interview>,
    
     <flow:interview name="Canada_Vaction_Request" finishLocation="{!URLFOR('/home/home.jsp')}">
        <apex:param name="var_UserId" value="{!$User.Id}"></apex:param>
        <apex:param name="var_Username" value="{!$User.FirstName} {!$User.LastName}"></apex:param>
    </flow:interview>
     
     )}
     
</apex:page>


any help would be much appericated. 

Thanks 
Hi, 

I am just wanting to be able to pass the current pages Name to my visualforce page, My visualforce page has a customer controller and is displaying a datatable, I can post both if there are any amendments to the code which might be needed. 

My end goal is to have a button on an account which someone can click and download any (Custom Object) Service Bookings meeting a critea matching the Account ID so that I can create a Proforma Invoice as a PDF. 

Thanks in advance. 
Hey, So I've been all over the forums and cannot seem to find the solution for this or where I am going. If anyone could shed any light on this it would be much appreciated.

What am trying to achieve: Validation of Picklist which cannot be (Blank) Here is what I've got so far:

AND ( 
$Label.Validation_Switch = "ON", 
Cancelled__c = True, 
(Case_ID__r.UK_Canada__c)= "UK", 
ISBLANK(Reason_for_Cancellation__c), 
TEXT(Reason_for_Job_Cancellations__c) <> "None", 
TEXT(Drill_Down_on_cancelled_reason__c) <> "None")​

Okay so the top couple of lines run and work absolutly fine but then when I place those 2 extra requirements in it accepts the code but validate anything. 

I've tried a few different things this is the last thing I tried and where I am currently stuck!

Any help would be massive on this.
Thanks