• Glyn Anderson 3
  • SMARTIE
  • 1249 Points
  • Member since 2017

  • Chatter
    Feed
  • 37
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 253
    Replies
We are using professional org.
Having a process builder which updates a field on some condition with formula type.

this is how the formula is ,i am using & between them.

I am having datetime field which is used in the update field but the format is being changed 


"Start Date:" & TEXT(DATETIMEVALUE([Opportunity].Date_Time_Start__c )) &
"End Date:" &TEXT([Opportunity].Date_Time_End__c ) &

This is the format i am lookinh for 
2/27/2018 4:00 PM

but this is how i am getting

2017-02-27 21:00:00Z 

How can i get this fixed?? 

 
On https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_expressions_operators_understanding.htm
it is stated that:

"Unlike Java, == in Apex compares object value equality, not reference equality, except for user-defined types."
"For sObjects and sObject arrays, == performs a deep check of all sObject field values before returning its result. Likewise for collections and built-in Apex objects." 

Why are the two asserts below failing then? If you look at the debug logs with the "Debug Only" option selected you should see that all 3 objects re identical.

Are the asserts below failing for you as well or is it just a glitch in my dev org?

// Two different ways to get a DescribeSObjectResult object 
        DescribeSObjectResult dsor1 = Account.SObjectType.getDescribe();
        DescribeSObjectResult dsor2 = Schema.sObjectType.Account;
        
        // Another way to get the DescribeSObjectResult using the Schema object
        List<DescribeSObjectResult> l =  Schema.describeSObjects(new List<String> {'Account'});
        DescribeSObjectResult dsor3 = l[0];
        
        System.assert(dsor1 == dsor2); // succeeds
       //System.assert(dsor1 == dsor3); // fails
      // System.assert(dsor2 == dsor3); // fails
       System.assert(dsor1.getsObjectType() == dsor3.getsObjectType()); // succeeds
       System.assert(dsor2.getsObjectType() == dsor3.getsObjectType()); // succeeds
        
        // If you look at the debug logs with the "Debug Only" option selected
        // you should see that the objects below are identical
        system.debug('dsor1: ' + dsor1);
        system.debug('dsor2: ' + dsor2);
        system.debug('dsor3: ' + dsor3);

 
I'm currently using an Apex Class to generate a list of records owned by a specific User.
 
public TelemarketerDialing(){

        if(ApexPages.currentpage().getParameters().get('leadgenerator') == null)
                       {myParam = UserInfo.getUserId();}

        else{myParam = ApexPages.currentpage().getParameters().get('leadgenerator');}
        }

      public String myParam { get; set; }

I build a Visualforce page for Managers to basically click in to the list of any User using the Visualforce page URL of that individual LeadGenerator's page.
 
<td><a href="https://corere--c.na50.visual.force.com/apex/DoorKnockerPortal?leadgenerator=0056A000000f0af">Angel</a></td>

        <td><a href="https://corere--c.na50.visual.force.com/apex/TelemarketerPortal?leadgenerator=0056A000000e779">Antonio</a></td>

        <td><a href="https://corere--c.na50.visual.force.com/apex/TelemarketerPortal?leadgenerator=0056A000001IVgU">Ary</a></td>
I'm wondering if there's a way to user the UserID to display the name of the User you are viewing on the page.

Something like:
public String LeadGeneratorName = getUserInfo(myParam).UserName;
Is this possible?


 
I have the following very simple VF page to display two dependent picklists (3 tiers total) using a custom controller. When I attempt to save the VF page, I get the error message above.
In the developer console, I see two Problems at Line 0. 1) ABS_Services_Input, Unknown property 'String.Services__c and 2) "Duplicate value found: duplicates value on record with id:" (Yes, literally. No id # given.)

<apex:page controller="ABSServicesController">
    <apex:messages style="color:red"></apex:messages>  
    <apex:form >
        <apex:pageBlock title="Dependent Picklist Entry">
            <apex:repeat value="{!serviceList}" var="svcItem">
                <apex:pageBlockSection title="{!svcItem.Services__c}" columns="1">
                    <apex:pageBlockSection title="{!svcItem.Capabilities__c}" columns="1">
                        <apex:pageBlockSection title="{!svcItem.Sub_Capabilities__c}" columns="1">
                        </apex:pageBlockSection>
                    </apex:pageBlockSection>
                </apex:pageBlockSection>
            </apex:repeat>
        </apex:pageBlock>
    </apex:form>
</apex:page> 

This is my Custom Controller code:

public with sharing class ABCServicesController{

    public String serviceList { get; set; }
 
    public List<ServiceOffered__c> servicesList{get;set;}
    public Map<String, Map<String, List<String>>> serviceMap{get;set;}
    
    public ABCservicesController(){
        serviceMap = new Map<String, Map<String, List<String>>>();
        
        servicesList = [Select ID, Services__c, Capabilities__c, Sub_Capabilities__c From ServiceOffered__c];
        
        for(ServiceOffered__c svcItem : servicesList) {
            if(serviceMap.containsKey(svcItem.Services__c)) {
                if(serviceMap.get(svcItem.Services__c).containsKey(svcItem.Capabilities__c)) {
                    serviceMap.get(svcItem.Services__c).get(svcItem.Capabilities__c).add(svcItem.Sub_Capabilities__c);
                } else {                    
                    serviceMap.get(svcItem.Services__c).put(svcItem.Capabilities__c, new List<String>{svcItem.Sub_Capabilities__c});
                }
            } else {
                Map<String, List<String>> m = new Map<String, List<String>>();
                m.put(svcItem.Capabilities__c, new List<String>{svcItem.Sub_Capabilities__c});
                serviceMap.put(svcItem.Services__c, m);
                //new Map<String, List<String>>{svcItem.Capabilities__c : new List<String>{svcItem.Capabilities__c}}
            }
        }
    }     
}

I do not know if it is relevant but earlier I was getting an unknow property error serviceList related to the line "Public List<ServiceOffered__c> serviceList{get;set;}".  
My path toward resolution, besides asking all of you great folks, is to figure out why the variable svcItem was expected to be something other than a string when every service being pulled into the List is a string.
Thanks in advance,
Wade
I am trying to cover a method which uses formula field.
This is my test class code:

SObject1__C coltype = new SObject1__C();
coltype.name = 'Name-3312';
insert coltype;
System.debug('--->SObject1.Name = '+coltype.name); // Gives 'Name-3312';

SObject2__C colObj = new SObject2__C();
colObj.SObject1__C = coltype.Id;
insert colObj;  

SObject3__C newCollP = new SObject3__C();
newCollP.SObject2__C = colObj.Id,
insert newCollP;

SObject3__C has a fomula field named 'Col_Type__C' which is evaluated as follows:
"SObject2__r.SObject1__r.Name"
System.debug('--->newCollP.Col_Type__C = '+ newCollP.Col_Type__C); //returns a2Hg0000001tqQ2

This 'Col_Type__C' field's value is then used in a method in a helper class which i am trying to cover. As posted by many, I have tried to query the object SObject3__C and populate the field Col_Type__C in the test class as below. But it's not populatting the formula field's value as 'Name-3312'. 
newCollP = [SELECT Id,SObject2__r.SObject1__r.Name, Col_Type__C from SObject3__C where Id=:newCollP.id];

When I debug Col_Type__C value in helper class it returns some ID. I need the value of  as name of SObject1__C.

What is missing in my code? How can I get the formula field populated? 

Any help is appreciated!
Hi all,

my problem is i have one last update date field.
i want to update this field on case record whenever i click on new task,log a call and new events on case record and also whnever i change status field and priority field it should be updated.

Thanks
Hi,
i am getting a post call out from external stsyem. i am creating or updating a  custom object record out of it. Can anyone please let em know how to write a test classs for it?
Here is my code:

global without sharing class ContactService {
    
    @HttpPost
    global static String insertContact(ContactInfoParser contactRec){
        //creation or update of application record. Mapping the fields from ContactInfoParser class.
        String RecordTypeApplicationId = Schema.SObjectType.Application__c.getRecordTypeInfosByName().get('Test').getRecordTypeId();        
        Application__c applicationObj = new Application__c();
        applicationObj.Id = contactRec.application.applicationId;
        applicationObj.applicant__c = contactRec.contact.contactId;
        applicationObj.RecordTypeId = RecordTypeApplicationId;
        applicationObj.assessPriorLearning__c = contactRec.application.assessPriorLearning;
        applicationObj.Status__c = contactRec.application.status;
        applicationObj.reason__c= contactRec.application.reason;
        applicationObj.priorLearningNotes__c= contactRec.application.priorLearningNotes;
        applicationObj.applingForCredit__c= contactRec.application.applingForCredit;
        upsert applicationObj;


Thanks
I am trying to insert portal user records and receiving this error


System.DmlException: Insert failed. First exception on row 0; first error: PORTAL_USER_ALREADY_EXISTS_FOR_CONTACT, portal user already exists for contact: []

Here is the code
 
@IsTest static void testRegFormWithNewUserAddress11() {
    
             
        Contact con = new Contact();
          con.Firstname = 'test';
          con.LastName ='test';
         con.OtherPhone = '8765432167';
         con.Organization_Type__c = 'test';
          con.Email ='Sitetestg466@hotmail.com';
        insert con; 
             Order__c ordr = new Order__c();
          ordr.Contact__c = con.Id;
          ordr.Account__c = a.Id;
          insert ordr;
          
       Order_Line__c ordrline = new Order_Line__c();
          ordrline.Order__c = ordr.id;
          insert ordrline;
             
    ControllerTest controller = new ControllerTest();        
controller.con = con;
        controller.acc = a;

       	controller.Password= 'testpass123';
        controller.checkIfContactExists();
        controller.checkIfAccountExists();
          
         controller.setTab();
 
          
             Profile p = [select Name, id From Profile where UserLicense.Name like '%Customer Community%' limit 1];
      
    		
           User u = new User ();
          u.FirstName = 'test';
          u.LastName ='test';
          u.Email ='testemail'+Math.round(Math.random()*Math.pow(10, 7))+'@testemail.com';
          u.Username = 'testemail'+Math.round(Math.random()*Math.pow(10, 8))+'@testemai.com';
          u.Alias ='test';
          u.CommunityNickname ='tst';
          u.ContactId =con.Id;
          u.LanguageLocaleKey = 'en_US';
                    u.LocaleSidKey ='en_CA';
                    u.TimeZoneSidKey ='America/Chicago';
         			u.ProfileId = p.Id;
                    u.EmailEncodingKey = 'UTF-8';
                 insert u; 
         
   
     }

The Controller code is below
 
List<User> existalready = [select id,Contact.FirstName,Username,Contact.LastName from user where username =:Email and IsActive = true LIMIT 1];
                if(existalready.size()<0){
                    for(User u: existalready){
insert u ;
insert con;

Can someone help in this scenario​
@isTest
public class MaintenanceRequestTest {
    
	
    @isTest static void testSetup(){
        
        
                List<Product2> equip = new List<Product2>();
        		equip.add(new Product2(Name ='Test Equipament', 
                                         Maintenance_Cycle__c = 10,
                                         Cost__c = 100,
                                         Current_Inventory__c = 10,
                                         Lifespan_Months__c = 10,
                                         Replacement_Part__c = true,
                                         Warehouse_SKU__c = 'abc'));
            
                        
                        insert equip;
        
        System.debug( 'Equip' + equip);
        
        Database.insert(equip, false);
        
        
        
    }
    
    @isTest static void testMaintenanceRequest(){
        
        MaintenanceRequestTest.testSetup();
        
        List<Case> listInsert = new List<Case>();
        
        List<Case> listUpdate = new List<Case>();
        
      	Id equipId = [SELECT Id FROM Product2 LIMIT 1].Id;
         System.debug('Product2' + equipId);
        
        
           for(Integer i = 0 ; i < 300; i++){
            Case caseInsert = new Case(Type='Routine Maintenance', Status = 'New', Origin = 'Phone');
			caseInsert.Equipment__c = equipId;            
        
            listInsert.add(caseInsert);
        }
        Database.insert(listInsert, false);
        
        
        Test.startTest();
        
        System.assertEquals(300, listInsert.size());
        
        
        for(Case c: listInsert){
            c.Status = 'Closed';
            listUpdate.add(c);
        }
        
        Database.update (listUpdate, false);
        
        System.assertEquals(300, listUpdate.size());
       
       
        
        User usuario = [SELECT id FROM User WHERE Id =: UserInfo.getUserId()];
              
    	System.runAs(usuario){
               
        	
             List<Case> ClosedCaseList = [SELECT Type, Status, Equipment__c, Date_Due__c, Date_Reported__c, Vehicle__c FROM Case WHERE status = 'Closed'];    
			
          	 MaintenanceRequestHelper.updateWorkOrders(ClosedCaseList);  
            
            }
        
       Test.stopTest(); 
    }
    
   
   
     	
}

 
i have a vf  page
<apex:page sidebar="false" showHeader="false" controller="definition_overview_controller" tabstyle="Label__c" id="page">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" />
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="/soap/ajax/15.0/connection.js" type="text/javascript"></script>
<script src="/soap/ajax/15.0/apex.js" type="text/javascript"></script>
<script>
function setFocusOnLoad() {}
$(document).ready(function(){
 $(".fieldInput").focusin(function() {
 var tempObj = $(this).closest('td').prev('td').find('input').val();
 if(tempObj.length >0){       
  sleep(100).then(()=>{
   sforce.connection.sessionId='{!GETSESSIONID()}';
   var tempList = sforce.apex.execute("ListofLabel","getAllLabels",{Objname:tempObj});
   $(".fieldInput").autocomplete({source: tempList});              
    });   
   }
});  
});

function sleep (time) {
    return new Promise((resolve) => setTimeout(resolve, time));
}       
</script>
<apex:sectionHeader title="Mapping Object" subtitle="Form" id="header"/>
<apex:form id="form">
<apex:pageBlock id="pageblock" >
 <apex:pageBlockTable title="Related List" value="{!label}" var="l" id="pageblocktable"> 
  <apex:column headerValue="Lebal Name" id="col1" >
      <apex:outputText value="{!l.name}">
     
       <apex:param value="{!l.name}" AssignTo="{!levelName}"/>
   </apex:outputText>
  </apex:column>
  
  <apex:column headerValue="SFobject" id="col2">
   <apex:inputText value="{!l.FormId__r.Parent_object_Name__c}">
   
       <apex:param value="{!l.formId__r.Parent_object_Name__c}" AssignTo="{!objectName}" />
   </apex:inputText>
  </apex:column>
  
  <apex:column headerValue="SFField" id="col3">
   <apex:inputText value="{!field}" styleClass="fieldInput"/>
  </apex:column>
  <apex:column >
          <apex:commandButton value="Save" action="{!save}"/>
  </apex:column>
  
 </apex:pageBlockTable>

    </apex:pageBlock>
</apex:form>
</apex:page>

controller:


public class definition_overview_controller{ 
 Mapping__c mapp=new Mapping__c();
 //list<Mapping__c> li{get;set;}
 
 public id i;
 public String field{get;set;}
 //public  string x{get;set;}
 public String levelname{get;set;}
 public string objectname{get;set;}
 
 public definition_overview_controller()
 {
  i=ApexPages.CurrentPage().getParameters().get('id');
  
 // li=new list<Mapping__c>();
  //li.add(mapp);
 }
 public list<label__C> label;
 public list<Label__c> getlabel()
 {
  label=[select Name,FormId__c,description__c,Label__c,FormId__r.Parent_object_Name__c from Label__c where FormId__c=:i];
  return label;
 }
 public void Save(){
 
   
            mapp.LabelD__c=levelname;
           // System.debug(mapp);
            mapp.SFObject__c=objectname;
            mapp.SFfield__c=field;
            insert mapp;
          //  li.add(mapp);
    /*      System.debug(li);
     for(integer i=0;i<li.size();i++)
     {
         insert li;
     }*/
         
  
 }
}

Note : i am not able to store multiple record at a time it show Error-->

Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [LabelID]: [LabelID]
Error is in expression '{!save}' in component <apex:commandButton> in page visualforcepage_webners_assignment_page2: Class.definition_overview_controller.Save: line 31, column 1
 
How do I solve this? 


Apex script unhandled trigger exception by user/organization: 005C0000008pPXs/00D80000000L8DR
 
RHX_Opportunity: execution of AfterInsert
 
caused by: System.SObjectException: Field Opps_Received_20163__c is not editable
 
Class.rh2.PS_Rollup_Context.setParentsToUpdate: line 571, column 1
Class.rh2.PS_Rollup_Context.run: line 510, column 1
Class.rh2.PS_Rollup_Helper.performSync: line 545, column 1
Class.rh2.ParentUtil.performTriggerRollups: line 128, column 1
Trigger.RHX_Opportunity: line 7, column 1
 
list<contact> clst = new list<contact>();
for(contact con : [Select id, otherphone from contact]) {
    con.otherphone = '768906543333';
    clst.add(con);
}
update clst;

Getting SOQL 101 Error Can Any one Correct Me. I am run this code in developer console
Hi,

This is challenge from Apex Academy: Fundamental Salesforce Coding Techniques by David Liu.
I want one child case but this trigger is creating Child case depending on the keywords like if I enter 2 keywords in Parent description, it will create 2 child cases.

Here is the trigger code
trigger CheckSecretInformation on Case (after insert, before update) {

	String childCaseSubject = 'Warning: Parent case may contain secret info';

	//Step 1: Create a collection containing each of our secret keywords
	Set<String> secretKeywords = new Set<String>();
	secretKeywords.add('Credit Card');
	secretKeywords.add('Social Security');
	secretKeywords.add('SSN');
	secretKeywords.add('Passport');
	secretKeywords.add('Bodyweight');

	//Step 2: Check to see if our case contains any of the secret keywords
	List<Case> casesWithSecretInfo = new List<Case>();
	List<String> SecretKeywordFound = new List<String>();
	for(Case myCase : Trigger.new) {
		if(myCase.Subject != childCaseSubject) {	
			for(String keyword : secretKeywords) {
				if(myCase.Description != null && myCase.Description.containsIgnoreCase(keyword)) {
					casesWithSecretInfo.add(myCase);
					SecretKeywordFound.add(keyword);
					System.debug('Case ' + myCase.Id + ' include secret keyword ' + keyword);
				}
			}
		}	
	}

	// Step 3: If our case contains a secret keyword, create a child case
	List<Case> casesToCreate = new List<Case>();
	
	for(Case caseWithSecretInfo : casesWithSecretInfo) {
		Case childCase        = new Case();
		childCase.subject     = childCaseSubject;
		childCase.ParentId    = caseWithSecretInfo.Id;
		childCase.IsEscalated = true;
		childCase.Priority    = 'High';
		childCase.Description = 'At least one of the following keywords were found ' + SecretKeywordFound;
		casesToCreate.add(childCase);
	
	}
	insert casesToCreate;

}

If I use break; in for loop, It will create one child case but it shows only first keyword not all the keyword that should be displays in one Child case.
 
trigger CheckSecretInformation on Case (after insert, before update) {

	String childCaseSubject = 'Warning: Parent case may contain secret info';

	//Step 1: Create a collection containing each of our secret keywords
	Set<String> secretKeywords = new Set<String>();
	secretKeywords.add('Credit Card');
	secretKeywords.add('Social Security');
	secretKeywords.add('SSN');
	secretKeywords.add('Passport');
	secretKeywords.add('Bodyweight');

	//Step 2: Check to see if our case contains any of the secret keywords
	List<Case> casesWithSecretInfo = new List<Case>();
	List<String> SecretKeywordFound = new List<String>();
	for(Case myCase : Trigger.new) {
		if(myCase.Subject != childCaseSubject) {	
			for(String keyword : secretKeywords) {
				if(myCase.Description != null && myCase.Description.containsIgnoreCase(keyword)) {
					casesWithSecretInfo.add(myCase);
					SecretKeywordFound.add(keyword);
					System.debug('Case ' + myCase.Id + ' include secret keyword ' + keyword);
					break;
				}
			}
		}	
	}

	// Step 3: If our case contains a secret keyword, create a child case
	List<Case> casesToCreate = new List<Case>();
	
	for(Case caseWithSecretInfo : casesWithSecretInfo) {
		Case childCase        = new Case();
		childCase.subject     = childCaseSubject;
		childCase.ParentId    = caseWithSecretInfo.Id;
		childCase.IsEscalated = true;
		childCase.Priority    = 'High';
		childCase.Description = 'At least one of the following keywords were found ' + SecretKeywordFound;
		casesToCreate.add(childCase);
	
	}
	insert casesToCreate;

}

Note: Please Don't use Map collection or SOQL. If there is a possibility that anyone can achieve this without MAP! 

Thanks