• Mario C
  • NEWBIE
  • 50 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 16
    Replies
Occasionally, I get some email notifications for the following. If Last name is mandatory and cannot be made optional, I wonder how I can resolve this. Any ideas?

The following errors were encountered while processing an incoming email:

FIELD_CUSTOM_VALIDATION_EXCEPTION : Error because :Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Last Name]: [Last 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. 
 

Hi,

I've implemented queueable apex on 2 chained classes: class a and class b. 

In Class A, when the class 2 gets invoked a list gets also passed into class b.

while the test cflass for class a is fine, I am unable to get coverage for class 2. 

Any ideas about how to write the test class for this scenario?
 
public class classA implements Queueable, Database.AllowsCallouts {

    
    public void execute(QueueableContext context) {

do something...

List<id> myList;

System.enqueueJob(new blassB(myList);

....

 
Ivecreated a class which gets called by an integration that creates an account, contact and case.

Unfortunately, I get CPU limit errors and I do not really know how to solve it. Any help would be much appreaciated.

Thanks!
 
public class HTTPChatContrSec {
  
        
    public HTTPChatContrSec(List<ID> x)
        
    {     

List<LC_chat__c> allChats = [Select id, extid__c,Existing_Member_Id__c,Existing_Lead_Id__c,Enquiry_Type__c, First_Name__c, Last_Name__c, Country__c, email_id__c, phone_no__c, notes__c, chat_id__c, chat_transcript__c, type_of_contact__c 
                          from lc_chat__c where id in :x limit 100];
        
        
        
    //define existing leads in chat__c and prepare for deletion 
        List<ID> leadIdToBeremoved = new List<ID>();
        List<lc_chat__c> leadChatRemovalList = New List<lc_chat__c>();
        List<Lead> leadRemovalList = New List<Lead>();

        for(lc_chat__c exLead: allChats){
            if(exLead.Type_of_Contact__c == 'Existing Lead'){
            leadIdToBeremoved.add(exLead.Existing_Lead_ID__c);
            leadChatRemovalList.add(exLead); 
        }//end of if
            } 
        delete leadChatRemovalList;
        
        List<Lead> leadToBeDeleted = [Select id from lead where id in :leadIdToBeremoved];
        
        for(Lead deletedLeads:leadToBeDeleted){
            leadRemovalList.add(deletedLeads);
        }
        delete leadRemovalList;
        
         //Existing Contact Case Creation Process
         List<sObject> newCases = new List<sObject>();
           for(lc_chat__c newChat:allChats){

            if(newChat.Type_of_Contact__c == 'Existing Member'){
        
                    
                	Case cs1 = new Case();
                    cs1.Subject = 'Lead Crushr Entry';
                    cs1.origin = 'Lead Crushr';
                    cs1.Description = newChat.notes__c + ' \n TRANSCRIPT: \n' + newChat.chat_transcript__c;
                    cs1.ContactId = newChat.Existing_Member_Id__c;
                    cs1.Type = newChat.Enquiry_Type__c;
                    cs1.Reason = 'Other';
            		//cs1.recordtypeid = SObjectType.Case.getRecordTypeInfosByDeveloperName().get('Master Record Type').getRecordTypeId();
            		cs1.Lead_Crushr_Record__c = newChat.id;
                
                	newCases.add(cs1);
            }//if condition for size() > 0 end here!
                	
            }
      
    
        
        

List<SObject> lstAccount = new List<SObject>(); 
//holds list of Contact
List<SObject> lstContacts = new List<SObject>();
//holds list of Cases
List<SObject> lstCase = new List<SObject>(); 
//final list for insertion
SObject[] sobjList = new List<SObject>();
//inserted records
List<ID> insList = new List<ID>();
           
String strInsertError = '';

//holds accountId and External Id in a Map
Map<String,String> accountContactMap = new Map<String,String>();
//holds contactId and External Id in a Map        
Map<String,String> contactCaseMap = new Map<String,String>();
 
//loop through the chats
for(Integer i=0; i<allChats.size();i++)
{
  Account accountObj = new Account();
  accountObj.lc_Id__c = allChats.get(i).extid__c; 
  accountObj.Name = allChats.get(i).last_name__c + ' Household';
  accountContactMap.put(accountObj.Name,accountObj.LC_ID__c);
  //finally add object to the list
  lstAccount.add(accountObj);
}
 
//loop through to create Contact record
for(Integer i=0;i<allChats.size();i++)
{
  Contact contactObj = new Contact(); 
  contactObj.LastName = allChats.get(i).last_name__c;
  contactObj.lc_ID__c = allChats.get(i).extid__c;
  contactObj.FirstName = allChats.get(i).first_name__c;
  contactObj.LeadSource = 'Lead Crushr';
  contactObj.Country_USE_ME__c = allChats.get(i).Country__c;
  contactObj.email = allChats.get(i).email_id__c;
  contactObj.phone = allChats.get(i).phone_no__c;
  contactObj.Newsletter__c = 'No';
  contactObj.Source_Type__c = 'Chat';
  contactCaseMap.put(contactObj.email,contactObj.lc_ID__c);


    
  // Create the parent reference.
  //check the Account Name in the map and retrieve the External Id from map
  if(accountContactMap.containsKey(allChats.get(i).last_name__c + ' Household'))
  {
   Account conReference = new Account(
   lc_Id__c =accountContactMap.get(allChats.get(i).last_name__c + ' Household')); 
   contactObj.Account = conReference;
      
  }  
  lstContacts.add(contactObj); 
}  
    
for(Integer i=0;i<allChats.size();i++)
{    
  Case caseObj = new Case(); 
  caseObj.Subject = 'Lead Crushr Entry';
  caseObj.origin = 'Lead Crushr';
  caseObj.Description = allChats.get(i).notes__c + ' \n TRANSCRIPT: \n \n' + allChats.get(i).chat_transcript__c;
  caseObj.Type = allChats.get(i).Enquiry_Type__c;
  caseObj.Reason = 'Other';
  caseObj.Lead_Crushr_Record__c = allChats.get(i).id;
  if(contactCaseMap.containsKey(allChats.get(i).email_id__c))
  {
   Contact casReference = new Contact(
   lc_Id__c =contactCaseMap.get(allChats.get(i).email_id__c)); 
   caseObj.Contact = casReference;

}
    lstCase.add(caseObj); 
       
}
  
    
//add account, contact and cases lists
sobjList.addAll(newCases);
sobjList.addAll(lstAccount);
sobjList.addAll(lstContacts);
sobjList.addAll(lstCase);


// Create the Account and the Contact in single DML.
Database.SaveResult[] results = Database.insert(sobjList);
// Check results.
for (Integer i = 0; i < results.size(); i++) {
  if (results[i].isSuccess()) 
  {
      insList.add(results[i].getId());
  System.debug('Successfully created ID: ' + results[i].getId());
  } 
  else 
  {
   System.debug('Error: could not create sobject ' + 'for array element ' + i + '.');
   strInsertError = 'The error reported was: ' + results[i].getErrors()[0].getMessage() + '\n';
   System.debug(strInsertError);
  }
} 
System.debug('strInsertError=' + strInsertError);
       
  
        
    }
                
            }

 
I've create a button to show all activities on lightining. It all works, but when I create the test class for the class, the code coverage of the class % remaing 0!

Here is the Class
public class ShowAllCaseActivity {
    
    Id caseId= ApexPages.currentPage().getParameters().get('Id');
 
public list <task> tasklist {get;set;}
    
public ShowAllCaseActivity(){
 
    if(caseId !=null ){
        
tasklist= [select id,Status,ActivityDate,Subject,Who.Name,What.Name,Description,LastModifiedDate,Owner.Name FROM Task WHERE WhatID=:caseId OR whoId=:caseId];
        
}
}
public PageReference cancel() {
    
PageReference ldPage = new PageReference('/'+caseId);
    
ldPage.setRedirect(true);
    
return ldPage;
}

}

and this is the test class...considering that I am still learning, I am pretty sure there is clearly something which I am missing:
 
@isTest
public class tstViewAllActivity {
    
static TestMethod void myShowAllCaseActivityTest()
  {
        Account acc = new Account();
            acc.Name ='TestAcc';
            insert acc;
        
            Contact cont = new Contact();
            cont.LastName ='Test';
            cont.accountId = acc.id;
            cont.Newsletter__c = 'false';
            cont.Email = 'test@test.ukic';
            cont.LeadSource = 'Email';
            cont.Source_Type__c = 'Salesforce';
            cont.Country_USE_ME__c = 'United Kingdom';
            cont.phone = '+44712345677';
            insert cont;

        Case caseObj = new Case();
        caseObj.Case_Reason__c = 'Couple';
        caseObj.Status = 'New';
        insert caseObj;

        
        Task myT = new Task();
        myT.Subject = 'Testme';
        myT.WhoId = cont.Id;
        myT.WhatId = caseObj.Id;
        myT.Status = 'Not Started'; 
        insert myT;
        }
        }

 
Hi All,

We are experiencing an odd one...I've created a formula field which conditionally shows membership level images on case according to contact membership level information. The image is appearing on all records correctly for me (system admin profile); when I log in as any user from my user account, the images are also shown correctly, but, strangely, when the actual users open the same record the images do not get shown!

Any ideas?
Hi All,

I've followed a tutorial about excluding specific domains in email to case, so that if an email from a specific domain is sent to the email2case email, a case won't get created. The application works great in Sandbox but I am struggling to move it to production as the test class seems to require some test entry for the custom metadata type and I am not really sure how to include that in the test class. 

Trigger:
//Tins trigger wiLL. be used to KiLL emaiLs coming via E2C and with certain domain names 2 
trigger AutoE2CCaseDeletion on Case (before insert) { 
    System.debug('Entered Kill Case trigger'); 
    SSK_RestrictedE2CDomains.killEmailToCase(Trigger.New); 
}



Here is the main class:
public with sharing class SSK_RestrictedE2CDomains {
	private static String SSK_RestrictedE2CDomains {
	get{
		return 'Restriced_E2C_Domains';
		
	}
}

private static Set<String> getSupportSetting(String settingName){
	Support_Setting__mdt supportSetting = [
	SELECT Value__c
	FROM Support_Setting__mdt
	WHERE DeveloperName = :settingName
	];
	

	Set<String> settingValues = new Set<String>();

	//settingValues.addAll(supportSetting.Value__c.split(','));
	return settingValues;
}

//Method to kiLL EmaiLs coming in from restricted Domains (E2C) 
public static void killEmailToCase (List<Case> lstCases){ 
	System.debug('killEmailToCase method successfully called'); 
	for(Case newCase: lstCases){ System.debug('Case ID: ' + newCase.Id); 
	System.debug('Case Origin: ' + newCase.Origin); 
	System.debug('Case From/Supplied/Web Email: ' + newCase.SuppliedEmail); 
	System.debug('Record Type name is: ' + newCase.RecordType.DeveloperName); 


//Read the "Restricted E2C Domains" from the Custom Metadata Types Labelled "Support Settings" 
Set<String> restrictedE2CDomains = getSupportSetting(SSK_RestrictedE2CDomains); 
if(newCase.SuppliedEmail != NULL && newCase.SuppliedEmail != 'email2casesmith@gmail.com'){ 
if(newCase.Origin == 'Email' && newCase.SuppliedEmail != NULL && newCase.SuppliedEmail.contains('@')) { 
//SpLit the EmaiL with DeLimiter as 1@' 
//So john.doe@gmaiL.com returns a List - ['fijohn.doe', 'gmaiL.com'] 
//Here the second index wiLL point to the Domain Name which is [1] 
List<String> emailParts = newCase.SuppliedEmail.split('@'); 
if(restrictedE2CDomains.contains(emailParts[1])){ 
	System.debug('Problematic case found and shouldnt be created'); 
	newCase.addError('Creation of cases with these domains are not allowed'); 
} 
} 
} 
} 
}		
}
TestClass1
@isTest 
private class tstE2CDomainNoKill {
	static testMethod void notKillCaseE2C_valid_domain(){

	Account newAcc = new Account();
	newAcc.Name = 'Test Account';
	Insert newAcc;

	Case newCase = new Case();
	newCase.AccountId = newAcc.Id;
	newCase.SuppliedEmail = 'test@gmail.com';
	newCase.Origin = 'Email';
	Insert newCase;
	System.assertNotEquals(NULL, newCase.Id);

	Case newCase2 = new Case();
	newCase.AccountId = newAcc.Id;
	newCase.SuppliedEmail = 'email2casesmith@gmail.com';
	newCase.Origin = 'Email';
	Insert newCase2;
	System.assertNotEquals(NULL, newCase2.Id);


		
	}
}

The above test class does fail and show the following text:

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AutoE2CCaseDeletion: execution of BeforeInsert

caused by: System.QueryException: List has no rows for assignment to SObject

Class.SSK_RestrictedE2CDomains.getSupportSetting: line 10, column 1
Class.SSK_RestrictedE2CDomains.killEmailToCase: line 33, column 1
Trigger.AutoE2CCaseDeletion: line 4, column 1: []
Any help/suggestion would highly be appreciated.

Thanks!




 

I can't get the following trigger to update the acount!

Can you pleas help me?
 
trigger UpdateMembershipLevelOnAccount on Contact (after update) {

	for(Contact con : Trigger.New) {
	List<Contact> conList;
	List<Contact> gm;
	List<Contact> sm;
	List<Contact> bm;
	String contactMembLevel;
	String accountMembLevel;

		conList = [Select ID, Member_Level__c, Account.Membership_Level_Text__c FROM Contact WHERE Account.Id = :con.Account.Id];
		
		if(conList.Size() <2 ){
			accountMembLevel = contactMembLevel;
		}

		else if(conList.Size() >1 ){


		for(Contact c: conList){
			contactMembLevel = con.Member_Level__c;
			accountMembLevel = con.Account.Membership_Level_Text__c;


			if(c.Member_Level__c == 'Gold'){
				gm.add(c);
				accountMembLevel = 'Gold';
			}
			else if(c.Member_Level__c == 'Silver'){
				sm.add(c);
				if(gm.size() <1 && sm.size() >0){
				accountMembLevel = 'Silver';
		}
					else {
				
				bm.add(c);
				accountMembLevel= 'Black';
			}
				}
				
				}
				
				}
}
}



 
Hi all,

I need to write a test class for a simple LEX component which I built, but I am struggling to understand how to write it. Can you please help me?
 
public class MyOLIController {
    
    @AuraEnabled
    public static List<OpportunityLineItem> getProduct(List<Id> opportunityIds){
        Case cs = [Select Enquiry__c from Case where Id=:opportunityIds];
        List<OpportunityLineItem> productList = [SELECT Id, Property__c, OpportunityId, Start_Date_Time__c,End_Date_Time__c,Status__c  
                                                 FROM OpportunityLineItem 
                                                 WHERE OpportunityId=:cs.Enquiry__c
                                                 AND (Status__c='confirmed' OR Status__c='pending' 
                                                                             OR Status__c='booked' 
                                                                             OR Status__c='stayed')];
        return productList;
    }
}

 
I managed to create a component which shows a list of opportunitylineitems. it works correctly when the component is placed on an opportunity page. What I now need to do is showing the OpportunityLineItems on a Case page, so I'd need the compinent to refer to the case lookup relationship (Opportunity__c) to show the opportunitylineitems.

Here is what I've done:

APEX Controller
public class MyOLIController {

    @AuraEnabled
    public static List<OpportunityLineItem> getProduct(List<Id> opportunityIds){
        List<OpportunityLineItem> productList = [SELECT Id, Property__c, OpportunityId, Start_Date_Time__c,End_Date_Time__c,Status__c 
                                                  FROM OpportunityLineItem WHERE OpportunityId in :opportunityIds];
        return productList;
    }
    
}

Component
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" controller = "MyOLIController" access="global" >
    
    <aura:handler name="init" action="{!c.getProductList}" value="{!this}" />
    <aura:attribute name="productList" type="List" />
    <lightning:card title="Line Items">
        <p class="slds-p-horizontal_small">
        <aura:iteration items="{!v.productList}" var="product">
            
            <lightning:recordViewForm recordId="{!product.Id}" objectApiName="OpportunityLineItem" > 
                <div class="slds-box slds=theme_default">
                <label for="HotelVilla">Hotel / Villa</label>
                <lightning:outputField aura:id="HotelVilla" fieldName="Property__c" variant="label-hidden"/>
                <label for="CheckIn">Check In Date</label>
                <lightning:outputField aura:id="CheckIn" fieldName="Start_Date_Time__c" variant="label-hidden"/>
                <label for="CheckOut">Check Out Date</label>
                <lightning:outputField aura:id="CheckOut" fieldName="End_Date_Time__c" variant="label-hidden" />
                <label for="BookingStatus">Booking Status</label>
                <lightning:outputField aura:id="BookingStatus" fieldName="Status__c" variant="label-hidden" />
                    </div>
            </lightning:recordViewForm>
            <br/>
            </aura:iteration>
        	</p>
     </lightning:card>
</aura:component>

Helper
({
	fetchProducts : function(component, event, helper) {
        var action = component.get("c.getProduct");
		var opportunityId = component.get("v.recordId");
        action.setParams({
            opportunityIds: opportunityId
        });
        action.setCallback(this, function(response){
            var state = response.getState();
            //State can be success, error or incomplete
            if(state == 'SUCCESS'){
                var productList = response.getReturnValue();
                console.log(productList);
                component.set("v.productList",productList);
            }
            else{
                alert('Error in getting data');
            }
        });
	
        $A.enqueueAction(action);
    }
   
})

 
  • September 28, 2018
  • Like
  • 0
The following query fetches the latest checkout date for each property among all products with status 'booked'.

The query returns the max date and related property ID. Is there a way to fetch the product ID (OpportunityLineItem ID) too? Unfortunatelly, if I add the Id to the query, I must also group by the Id field. 
SELECT MAX(End_Date_Time__c) latestCheckOut, Property__c Property
                      FROM OpportunityLineItem 
                      WHERE OpportunityId = :oli.OpportunityId AND Status__c = 'booked'
                      GROUP BY Property__c

User-added image
  • September 26, 2018
  • Like
  • 0
Hi All,

I need to write a trigger on contact which will update the phone number when the the country code is not included in the number. 

I thought that I could achieve this through Custom settings. I've got a custom settings call Country_letter_codes__c already setup. it includes 3 fields:
Country__c (name of the country in full)
Letter_Code__c (ISO code for each country - i.e. United Kingdom = GB)
Phone_Code__c (I've added this for my task and I populated it with all the corresponding phone codes i.e. Country__c = United Kingdom, Phone_code__c  = +44...) 

This cs is currently used to update the MailingCountry with a corresponding Letter_Code (i.e. from United Kingdom to GB), but I thought about using it for updating the contact phone too, and that is why I added a new field for Phone_Code__c. 

Considering that I actually know how to write the code to update the number itself, I actually need to understand how to run a sort of vertical lookup on Letter_Code. Basically I need to find the contact MailingCountry (which is actually a letter_code) in the cs.letter_code and fetch the corresponding phone code, so that I can then append it to he phone number wher required.  
  • September 10, 2018
  • Like
  • 0

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 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. 
 

Hi,

I've implemented queueable apex on 2 chained classes: class a and class b. 

In Class A, when the class 2 gets invoked a list gets also passed into class b.

while the test cflass for class a is fine, I am unable to get coverage for class 2. 

Any ideas about how to write the test class for this scenario?
 
public class classA implements Queueable, Database.AllowsCallouts {

    
    public void execute(QueueableContext context) {

do something...

List<id> myList;

System.enqueueJob(new blassB(myList);

....

 
Hi All,

We are experiencing an odd one...I've created a formula field which conditionally shows membership level images on case according to contact membership level information. The image is appearing on all records correctly for me (system admin profile); when I log in as any user from my user account, the images are also shown correctly, but, strangely, when the actual users open the same record the images do not get shown!

Any ideas?
Hi All,

I've followed a tutorial about excluding specific domains in email to case, so that if an email from a specific domain is sent to the email2case email, a case won't get created. The application works great in Sandbox but I am struggling to move it to production as the test class seems to require some test entry for the custom metadata type and I am not really sure how to include that in the test class. 

Trigger:
//Tins trigger wiLL. be used to KiLL emaiLs coming via E2C and with certain domain names 2 
trigger AutoE2CCaseDeletion on Case (before insert) { 
    System.debug('Entered Kill Case trigger'); 
    SSK_RestrictedE2CDomains.killEmailToCase(Trigger.New); 
}



Here is the main class:
public with sharing class SSK_RestrictedE2CDomains {
	private static String SSK_RestrictedE2CDomains {
	get{
		return 'Restriced_E2C_Domains';
		
	}
}

private static Set<String> getSupportSetting(String settingName){
	Support_Setting__mdt supportSetting = [
	SELECT Value__c
	FROM Support_Setting__mdt
	WHERE DeveloperName = :settingName
	];
	

	Set<String> settingValues = new Set<String>();

	//settingValues.addAll(supportSetting.Value__c.split(','));
	return settingValues;
}

//Method to kiLL EmaiLs coming in from restricted Domains (E2C) 
public static void killEmailToCase (List<Case> lstCases){ 
	System.debug('killEmailToCase method successfully called'); 
	for(Case newCase: lstCases){ System.debug('Case ID: ' + newCase.Id); 
	System.debug('Case Origin: ' + newCase.Origin); 
	System.debug('Case From/Supplied/Web Email: ' + newCase.SuppliedEmail); 
	System.debug('Record Type name is: ' + newCase.RecordType.DeveloperName); 


//Read the "Restricted E2C Domains" from the Custom Metadata Types Labelled "Support Settings" 
Set<String> restrictedE2CDomains = getSupportSetting(SSK_RestrictedE2CDomains); 
if(newCase.SuppliedEmail != NULL && newCase.SuppliedEmail != 'email2casesmith@gmail.com'){ 
if(newCase.Origin == 'Email' && newCase.SuppliedEmail != NULL && newCase.SuppliedEmail.contains('@')) { 
//SpLit the EmaiL with DeLimiter as 1@' 
//So john.doe@gmaiL.com returns a List - ['fijohn.doe', 'gmaiL.com'] 
//Here the second index wiLL point to the Domain Name which is [1] 
List<String> emailParts = newCase.SuppliedEmail.split('@'); 
if(restrictedE2CDomains.contains(emailParts[1])){ 
	System.debug('Problematic case found and shouldnt be created'); 
	newCase.addError('Creation of cases with these domains are not allowed'); 
} 
} 
} 
} 
}		
}
TestClass1
@isTest 
private class tstE2CDomainNoKill {
	static testMethod void notKillCaseE2C_valid_domain(){

	Account newAcc = new Account();
	newAcc.Name = 'Test Account';
	Insert newAcc;

	Case newCase = new Case();
	newCase.AccountId = newAcc.Id;
	newCase.SuppliedEmail = 'test@gmail.com';
	newCase.Origin = 'Email';
	Insert newCase;
	System.assertNotEquals(NULL, newCase.Id);

	Case newCase2 = new Case();
	newCase.AccountId = newAcc.Id;
	newCase.SuppliedEmail = 'email2casesmith@gmail.com';
	newCase.Origin = 'Email';
	Insert newCase2;
	System.assertNotEquals(NULL, newCase2.Id);


		
	}
}

The above test class does fail and show the following text:

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AutoE2CCaseDeletion: execution of BeforeInsert

caused by: System.QueryException: List has no rows for assignment to SObject

Class.SSK_RestrictedE2CDomains.getSupportSetting: line 10, column 1
Class.SSK_RestrictedE2CDomains.killEmailToCase: line 33, column 1
Trigger.AutoE2CCaseDeletion: line 4, column 1: []
Any help/suggestion would highly be appreciated.

Thanks!




 

I can't get the following trigger to update the acount!

Can you pleas help me?
 
trigger UpdateMembershipLevelOnAccount on Contact (after update) {

	for(Contact con : Trigger.New) {
	List<Contact> conList;
	List<Contact> gm;
	List<Contact> sm;
	List<Contact> bm;
	String contactMembLevel;
	String accountMembLevel;

		conList = [Select ID, Member_Level__c, Account.Membership_Level_Text__c FROM Contact WHERE Account.Id = :con.Account.Id];
		
		if(conList.Size() <2 ){
			accountMembLevel = contactMembLevel;
		}

		else if(conList.Size() >1 ){


		for(Contact c: conList){
			contactMembLevel = con.Member_Level__c;
			accountMembLevel = con.Account.Membership_Level_Text__c;


			if(c.Member_Level__c == 'Gold'){
				gm.add(c);
				accountMembLevel = 'Gold';
			}
			else if(c.Member_Level__c == 'Silver'){
				sm.add(c);
				if(gm.size() <1 && sm.size() >0){
				accountMembLevel = 'Silver';
		}
					else {
				
				bm.add(c);
				accountMembLevel= 'Black';
			}
				}
				
				}
				
				}
}
}



 
Hi all,

I need to write a test class for a simple LEX component which I built, but I am struggling to understand how to write it. Can you please help me?
 
public class MyOLIController {
    
    @AuraEnabled
    public static List<OpportunityLineItem> getProduct(List<Id> opportunityIds){
        Case cs = [Select Enquiry__c from Case where Id=:opportunityIds];
        List<OpportunityLineItem> productList = [SELECT Id, Property__c, OpportunityId, Start_Date_Time__c,End_Date_Time__c,Status__c  
                                                 FROM OpportunityLineItem 
                                                 WHERE OpportunityId=:cs.Enquiry__c
                                                 AND (Status__c='confirmed' OR Status__c='pending' 
                                                                             OR Status__c='booked' 
                                                                             OR Status__c='stayed')];
        return productList;
    }
}

 
I managed to create a component which shows a list of opportunitylineitems. it works correctly when the component is placed on an opportunity page. What I now need to do is showing the OpportunityLineItems on a Case page, so I'd need the compinent to refer to the case lookup relationship (Opportunity__c) to show the opportunitylineitems.

Here is what I've done:

APEX Controller
public class MyOLIController {

    @AuraEnabled
    public static List<OpportunityLineItem> getProduct(List<Id> opportunityIds){
        List<OpportunityLineItem> productList = [SELECT Id, Property__c, OpportunityId, Start_Date_Time__c,End_Date_Time__c,Status__c 
                                                  FROM OpportunityLineItem WHERE OpportunityId in :opportunityIds];
        return productList;
    }
    
}

Component
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" controller = "MyOLIController" access="global" >
    
    <aura:handler name="init" action="{!c.getProductList}" value="{!this}" />
    <aura:attribute name="productList" type="List" />
    <lightning:card title="Line Items">
        <p class="slds-p-horizontal_small">
        <aura:iteration items="{!v.productList}" var="product">
            
            <lightning:recordViewForm recordId="{!product.Id}" objectApiName="OpportunityLineItem" > 
                <div class="slds-box slds=theme_default">
                <label for="HotelVilla">Hotel / Villa</label>
                <lightning:outputField aura:id="HotelVilla" fieldName="Property__c" variant="label-hidden"/>
                <label for="CheckIn">Check In Date</label>
                <lightning:outputField aura:id="CheckIn" fieldName="Start_Date_Time__c" variant="label-hidden"/>
                <label for="CheckOut">Check Out Date</label>
                <lightning:outputField aura:id="CheckOut" fieldName="End_Date_Time__c" variant="label-hidden" />
                <label for="BookingStatus">Booking Status</label>
                <lightning:outputField aura:id="BookingStatus" fieldName="Status__c" variant="label-hidden" />
                    </div>
            </lightning:recordViewForm>
            <br/>
            </aura:iteration>
        	</p>
     </lightning:card>
</aura:component>

Helper
({
	fetchProducts : function(component, event, helper) {
        var action = component.get("c.getProduct");
		var opportunityId = component.get("v.recordId");
        action.setParams({
            opportunityIds: opportunityId
        });
        action.setCallback(this, function(response){
            var state = response.getState();
            //State can be success, error or incomplete
            if(state == 'SUCCESS'){
                var productList = response.getReturnValue();
                console.log(productList);
                component.set("v.productList",productList);
            }
            else{
                alert('Error in getting data');
            }
        });
	
        $A.enqueueAction(action);
    }
   
})

 
  • September 28, 2018
  • Like
  • 0
Hi All,

I need to write a trigger on contact which will update the phone number when the the country code is not included in the number. 

I thought that I could achieve this through Custom settings. I've got a custom settings call Country_letter_codes__c already setup. it includes 3 fields:
Country__c (name of the country in full)
Letter_Code__c (ISO code for each country - i.e. United Kingdom = GB)
Phone_Code__c (I've added this for my task and I populated it with all the corresponding phone codes i.e. Country__c = United Kingdom, Phone_code__c  = +44...) 

This cs is currently used to update the MailingCountry with a corresponding Letter_Code (i.e. from United Kingdom to GB), but I thought about using it for updating the contact phone too, and that is why I added a new field for Phone_Code__c. 

Considering that I actually know how to write the code to update the number itself, I actually need to understand how to run a sort of vertical lookup on Letter_Code. Basically I need to find the contact MailingCountry (which is actually a letter_code) in the cs.letter_code and fetch the corresponding phone code, so that I can then append it to he phone number wher required.  
  • September 10, 2018
  • Like
  • 0