• Waleed Khan 8
  • NEWBIE
  • -1 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 5
    Replies
User-added image




An above Image is custom component which holds certain value of a country now I needed that just next to an individual values ,countries flag should be get visible how couuld we achieve this not sure...
any suggestion would be appreciable.

Note :-
Combo box values 

1. USA    (USA Flag)
2. CANADA    (Canada Flag)
3. UK (Uk Flag)
 
This is COmponent Code :- 



<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
	<aura:attribute
        name="modes"
        type="List"
        default="[
                 {'label': 'None', 'value': 'none'  } ,
                 {'label': 'UK', 'value': 'uk'  } ,
                 
         
    {'label': 'CANADA', 'value': 'canada'},
    {'label': 'USA','value': 'us'},
    ]"
    />
    <lightning:card  class="slds-align_absolute-center" title="SELECT COUNTRY">
        
        <lightning:layout horizontalAlign="center" multipleRows="true">
            <lightning:layoutItem padding="around-small" class="slds-align_absolute-center">
               
                <lightning:combobox
                    name="Country"
                    label="Game Mode"
                    value="inProgress"
                    variant="label-hidden"
                    aura:id="Country"
                    options="{!v.modes}"
                    placeholder="Select Countries"
                                    onchange = "{!c.handlechanged}"
                                     
                />
            </lightning:layoutItem>
        </lightning:layout>
    </lightning:card>
</aura:component>

 
Hello! I'm just now digging into Apex Triggers, and I'm having a little trouble with creating tests. Here's my Apex class:
trigger CanceledProgram on Program__c (before update) {
	Program__c pNew = Trigger.new[0];
    Program__c pOld = Trigger.oldMap.get(pNew.id);
    
    if(pNew.Canceled__c != pOld.Canceled__c && pNew.Canceled__c == true){
        System.debug('Updated to True');
        System.debug('New value = ' + pNew.Canceled__c);
        System.debug('Old value = ' + pOld.Canceled__c);
        
        if(pOld.Name.length() <= 70){
            pNew.Name = 'CANCELED: ' + pNew.Name;
            System.debug('New name length: '+pNew.Name.length());
            System.debug('Old name length: '+pOld.Name.length());
            System.debug(pNew.Name);
        } else if (pOld.Name.length() > 70){
            String pNameShort = pNew.Name.substring(0, 65) + '...';
            pNew.Name = 'CANCELED: ' + pNameShort;
            System.debug(pNew.Name);
            System.debug(pNew.Name.length());
        }
        
        
    } else if (pNew.Canceled__c != pOld.Canceled__c && pNew.Canceled__c == false) {
        System.debug('Updated to False');
        System.debug('New value = ' + pNew.Canceled__c);
        System.debug('Old value = ' + pOld.Canceled__c);
        if(pNew.Name.startsWith('CANCELED: ')){
            pNew.Name = pNew.Name.substring(10);
        }
        
        
    } else {
        System.debug('The Canceled Field was not changed');
    }
    
    if (pNew.Name != pOld.Name && pOld.Name.length() >70){
        
        System.debug(pOld.Name.length());
        System.debug(pNew.Name.length());
    }
        
}

And see below for the test class. It says I have 100% coverage, but that the 3/4 tests failed. I assume they need to succeed in order to push this class to production. I don't understand why they didn't pass though? In the first test method, I did a little testing, trial, and error with using System.debug to double check the values, and the test should be passing. Can anyone tell me what I'm doing wrong? Thanks for any help you can provide!
 
@isTest
private class CanceledProgramTest {     

    @isTest static void TestCanceledProgramWithShortName() {
        Program__c p1 = new Program__c(Name='Will not happen');
        insert p1;
        
        p1 = [SELECT Id, Name, Canceled__c FROM Program__c WHERE Id = :p1.Id];
        System.debug(p1);
        Test.startTest();
        p1.Canceled__c = true;
        update p1;
        System.assertEquals('CANCELED: Will not happen', p1.Name);
        Test.stopTest();
    }
    
    @isTest static void TestCanceledProgramWithLongName() {
        Program__c p = new Program__c(Name='This program will not happen. I am sorry, but this program just will not happen.');
        insert p;
        p.Canceled__c = true;
        update p;
        System.assertEquals('CANCELED: This program will not happen. I am sorry, but this program just w...', p.Name);
    }
    
    @isTest static void TestUnCanceledProgramChangeName() {
        Program__c p = new Program__c(Name='CANCELED: We will have it after all. Name changes.', Canceled__c = true);
        insert p;
        p.Canceled__c = false;
        update p;
        System.assertEquals('We will have it after all. Name changes.', p.Name);
    }
    
    @isTest static void TestUnCanceledProgramSameName() {
        Program__c p = new Program__c(Name='We will have it after all. Name is same.' , Canceled__c = true);
        insert p;
        p.Canceled__c = false;
        update p;
        System.assertEquals('We will have it after all. Name is same.', p.Name);
    }
}

 

I am creating a rather complex questionnaire in flow. 

I've noticed a rather odd behaviuor...see the following example:

Q1. Do you have kids?
Yes/No (choice Yes=Truie, choice No=False)

Q2. are you kids at school? (the component visibility for this Q is set if Q1=Yes)
Yes/No

Now, I can finally create a kids profile record

The Kids Profile object includes Q1 and Q2 checkboxes so that I can map to the actual screen questions.

Here is the problem, if I map both Q1 and Q2 on the create records component, but the response for Q1 happens to be No, Q2 gets skipped and in the debug Q2 results to be a null, and consequently a  INVALID_TYPE_ON_FIELD_IN_RECORD error will occur. 

Considering that I know why the error is being triggered, I believe that for a screen funtionality, there should actually be something that ignore the mapping for skipped questions; I can't believe this is not a stardad functionality...

Please let me know if it's just me that I am missing something or it's really like that. 
 

I am looking to map the Lead Record Type to the Opportunity Record Type when I convert the lead. Right now the Opportunity Record Type populates with a default value. I have only written a few apex triggers as of now and am still new to salesforce, I appreciate any help! 

I have an issue with a trigger that grabs a date/time value from one field (Field 1)and populates it in another (Field 2). The issue I run into is that if Field 1 is empty I get an error which I am guessing is cause you can insert a null value in a time/date field. Is there a to leave the field blank?

 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger Previous_Notes caused an unexpected exception, contact your administrator: Previous_Notes: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.Previous_Notes: line 27, column 1

 

trigger Previous_Notes on Event (before insert) {
    

Set<ID> trEvent = New Set<ID>();
Map<ID, Event> mAccEvent = New Map<ID, Event>();

//Get list of WhatIDs in trigger
for(Event e : trigger.new)
    trEvent.add(e.whatID);

List<Event> lEvent = [SELECT id, Event.WhatID,Event.Previous_Completed_Date_Time__c,Event.Completed_Date_Time_-c,Event.Previous_Notes__c,Event.Relevant_Notes__c FROM Event WHERE (whatID IN :trEvent) and (Subject = 'Outside Sales Call') and  (Sales_Call_Completed__c ='Yes' ) AND (Relevant_Notes__c != ' ') ORDER BY Completed_Date_Time__c DESC];

//Populate MAP with WhatIDs to the list of events
For (Event e : lEvent){
      If(mAccEvent.get(e.whatID) == Null ) 
         mAccEvent.put(e.WhatID, e);
}

System.Debug('mAccEvent ' + mAccEvent);

for (Event updatedEvent : trigger.new) {   

System.Debug('updatedEvent.whatID = ' + updatedEvent.whatID);


If(mAccEvent.containsKey(updatedEvent.whatID) == TRUE) updatedEvent.Previous_Notes__c = mAccEvent.get(updatedEvent.whatID).Relevant_Notes__c  ; 
updatedEvent.Previous_Completed_Date_Time__c = mAccEvent.get(updatedEvent.whatID).Completed_Date_Time__c ;
}

//This should get most recent events with whatIDs that are the sames as all the whatIDs in the trigger. Then it will populate a map using those whatIDs. In the last for loop it will update each record in the trigger with the Previous_Notes__c value from the 1 event with a matching whatID. 

}

 

  • November 07, 2011
  • Like
  • 0