• matt.ian.thomas
  • NEWBIE
  • 140 Points
  • Member since 2015
  • Salesforce Architect
  • ContextMedia, Inc.


  • Chatter
    Feed
  • 4
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 26
    Replies
Hi all,

I am working on a trigger on the Contract object which creates Events and Orders associated with the activation of a contract. My trigger is throwing an error when I try to assign the ContractId to my newly created Order object. The error does not occur when I assign the ContractId to my Event object, however. Any tips on how to work around this?

Here are some code snippets (Note that 'temp' is a local variable of type Contract):

This code generates the error:
Order o1 = new Order(AccountId = temp.AccountId, EffectiveDate = temp.Requested_First_Service__c, 
                                 ContractId = temp.Id, <---PROBLEM CODE
                                 Status = 'Draft');
Accompanying Event creation code, this does not generate an error:
Event e1 = new Event(WhatId = temp.AccountId, AccountOrSite__c = temp.AccountId, 
                                 Contract__c = temp.Id, 
                                 StartDateTime = temp.Requested_First_Service__c, EndDateTime = te                                        mp.Requested_First_Service__c + 7, 
                                 Subject = 'Initial Followup');

Here is the error generated:
Validation Errors While Saving Record(s)
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger StaggeredEventCreation caused an unexpected exception, contact your administrator: StaggeredEventCreation: execution of BeforeUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 8003B000000DDyx) is currently in trigger StaggeredEventCreation, therefore it cannot recursively update itself: []: Trigger.StaggeredEventCreation: line 67, column 1".
Any tips?
Thank you.


 
I have included jQuery as Static Resource and it is working with the Visualforce page when I include my own JavaScript code in <script type="text/javascript"> tag.

However, if I copy/paste the code into a .js file and upload it on static resource and include the file as apex:includeScript value, the JavaScript code never worked.

On the Visualforce page, I wrote jQuery.noConflict(); and use jQuery instead of '$' to make it work.

Later when I copied the original code into a .js file, I did not change anything. It did not work. Then I tried to use something like var j$ = jQuery.noConflict(); and replace all jQuery by j$. Not working. I also tried to delete the noConflict line and all using '$' as selector. Not working. Another try is to add (function($) {  }) (jQuery); to wrap the original code. Still not working.

Is there anything that I am mising to make the external js file which references jQuery working with the visualforce page?
Hi, 

 I want to put below code inside after update after insert triger Please help me how to add below code into trigger am finding difficult in adding in inside trigger I need to pass trigger.new values in soql query.

Everytime when i make a update in lead it must look inside territory_lookup__c object to get values and update. 
 
for (lead ulds : [select id,postalcode,state,country from lead where id = '00Q180000029Ujz' limit 1])
 {
   ulds.postalcode = '';
   ulds.country = 'India';
   update ulds;
 }

 List<Territory_Lookup__c> territoryLookupList = null;  
 List<Integer> gzip = new List<Integer>(); // we need a list so that we can sort it.
 list<String> gstate = new list<String>();
 list<String> gcountry = new list<String>(); 
 
 for(Lead l :  [select id,postalcode,state,country from lead where id = '00Q180000029Ujz' limit 1]){
  gstate.add(l.state);
  gcountry.add(l.country);
  
   if ( l.postalcode != null)
   {
   gzip.add(Integer.valueof(l.postalcode));
   }
   else
   {
    gzip.add(0);
    }
 }

  system.debug('Zip :' + gzip);
  system.debug('State :' + gstate);
  system.debug('Country :' + gcountry);
 
  

  Territory_Lookup__c tls = [select Theater__c,Region__c,Area__c,User__c FROM Territory_Lookup__c
                           where  ( Zip_Start__c <= :gzip and Zip_End__c >=:gzip )  or
                                  (Country__c = :gcountry )
                                  limit 1]; 
    
  system.debug('Theater :' + tls.Theater__c);
  system.debug('Area :' + tls.Region__c);
  system.debug('Region :' + tls.Area__c);


  for(lead uld : [select id,postalcode,state,country from lead where id = '00Q180000029Ujz' limit 1]){
 
 
     uld.Territory_Lookup__c = tls.id;
     uld.Territory_Area__c = tls.Area__c;
     uld.Territory_Region__c = tls.Region__c;
     uld.Territory_Theater__c = tls.Theater__c;
 
      update uld;
   }

Thanks
Sudhir
I am asking this question for our Developer, i am an Admin.

We have some code on the account layout that does a calculation on the Assets object.  Serves as a rollup since we cannot directly do a rollup summary.  The code works, the only issue is an Asset must be "touched" in order for the code to do its job.  The question is how can we get the code to run it's calculation without having to manually edit and save an asset?  
I have a visualforce page which overrides the standard view action for Case. The page has <apex:details> and when it loads in Console none of the standard links rendered on the page layout work (for example, "edit" on a related list item). This happens only in Google Chrome and the following error is thrown:

"Uncaught SecurityError: Blocked a frame with origin "https://c.na8.visual.force.com" from accessing a frame with origin "https://na8.salesforce.com". Protocols, domains, and ports must match."

Which leads to the following source:
function srcUp(url) {
    if (window.parent && window.parent.srcFromMain) {
        window.parent.srcFromMain(url);
    } else {
        srcSelf(url);
    }
}

Has anyone seen this before and know what the cause was? I suspect that some of the custom JS I've included in the page could be the issue, but I'm not entirely sure where to start looking since I can't recall during development exactly when it popped up. Thanks!
I have a visualforce page called CaseDetails which overrides the standard View action for Case. Boiled down, the markup is the following:
 
<apex:tabPanel switchType="client">
	<apex:tab label="Details" name="caseDetails">
		<apex:detail inlineEdit="true"/>
	</apex:tab>

On the page layout, there are two sections which have a visualforce page on them. When the page loads, they do not render. Has anyone else had this happen before and understand what the cause is?
I have a puzzling issue that I cannot figure out. I have a very simple REST service running on an external server returning a small JSON response for every GET request. It is set up as a simple service to verify I can connect to it from Salesforce. This service returns without issue when hit from a browser, CURL, etc. However, when we try from Salesforce, it takes a number of tries to get a return. Here is the simple Apex code I've wrote the check the service:
 
Http h = new Http();
HttpRequest req = new HttpRequest();
String url = '<webservice being called>';
req.setEndpoint(url);
req.setMethod('GET');
HttpResponse res;
while(res == null){   
	try{
		res = h.send(req);
		System.debug(res.getBody());  
	} catch(CalloutException e) {
		System.debug(e.getMessage());
	}
}

When running this section of code, there are a number of times "Read timed out" happens when making the HttpResponse call before a successful response is received. Here are a couple examples of an output from the logs:

User-added image

Success request after 1 attempt

As you can see, there is no reason or frequency for the timeouts. I have control over the server that is accepting the requests but unfortuantely I do not have control over the network level firewall. I have been told there are no restrictions to the network for any and all traffic. That seems to be the case because calls can be made from everywhere with issues. On the server logs, I see a successful request coming in but do not see any requests when there is a timeout.

Is there anything from the Salesforce side that could be causing this issue? I want to make sure I cover all possible points in this process that could be causing this failure. 
Hello All,
I am trying to implement S2S (Salesforce to salesforce) And I have written a code on Custom object called "ABC" to allow auto forwarding of records. After making the trigger active, I cannot manually create any records. Please help.

trigger SendABCToConnection on ABC__c(after insert,after update) {
        PartnerNetworkConnection conn = [select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection  where ConnectionStatus = 'Accepted' and ConnectionName = 'XYZ'];
        List<PartnerNetworkRecordConnection> recordConnectionToInsert  = new List<PartnerNetworkRecordConnection>  ();
        for (ABC__c acc : Trigger.new){
            PartnerNetworkRecordConnection newrecord = new PartnerNetworkRecordConnection();

            newrecord.ConnectionId = conn.Id;
            newrecord.LocalRecordId = acc.id;  
            newrecord.SendClosedTasks = false;
            newrecord.SendOpenTasks = false;
            newrecord.SendEmails = false;
            recordConnectionToInsert.add(newrecord);
        }
        if (recordConnectionToInsert.size() > 0){
            System.debug('>>> Sharing ' + recordConnectionToInsert.size() + ' records');
            insert recordConnectionToInsert;
        }
     }

The error I am getting:
Apex trigger SendABCToConnection caused an unexpected exception, contact your administrator: SendABCToConnection: execution of AfterInsert caused by: System.QueryException: List has more than 1 row for assignment to SObject: Trigger.SendABCToConnection: line 2, column 1
Hello Guys,  i hope somebody can help me ;) I wrote this trigger ( i am a new "developer"^^). Now i need a Test Class for this Trigger to run in our Production. I have no idea how to start :( Maybe its easy but for me .. so pleas help me guys :)

User-added image
Hi all,

I am working on a trigger on the Contract object which creates Events and Orders associated with the activation of a contract. My trigger is throwing an error when I try to assign the ContractId to my newly created Order object. The error does not occur when I assign the ContractId to my Event object, however. Any tips on how to work around this?

Here are some code snippets (Note that 'temp' is a local variable of type Contract):

This code generates the error:
Order o1 = new Order(AccountId = temp.AccountId, EffectiveDate = temp.Requested_First_Service__c, 
                                 ContractId = temp.Id, <---PROBLEM CODE
                                 Status = 'Draft');
Accompanying Event creation code, this does not generate an error:
Event e1 = new Event(WhatId = temp.AccountId, AccountOrSite__c = temp.AccountId, 
                                 Contract__c = temp.Id, 
                                 StartDateTime = temp.Requested_First_Service__c, EndDateTime = te                                        mp.Requested_First_Service__c + 7, 
                                 Subject = 'Initial Followup');

Here is the error generated:
Validation Errors While Saving Record(s)
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger StaggeredEventCreation caused an unexpected exception, contact your administrator: StaggeredEventCreation: execution of BeforeUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 8003B000000DDyx) is currently in trigger StaggeredEventCreation, therefore it cannot recursively update itself: []: Trigger.StaggeredEventCreation: line 67, column 1".
Any tips?
Thank you.


 
Hi,

How do I quickly download / export a Country & Region picklist I've amended in Salesforce. There doesn't seem to be a quick way of exporting this basic set of data?

Thanks

​Robert
I have a form with over 400 picklist values. They are alphabetical, but still, to scroll all the way down might be tedious. Does anyone know how to create a form where someone starts typing what they think applies to them, and the list of things that match what they are typing (based on what values are in the picklist) start to pop up? or just a more traditional search function that returns applicable results? Suggests to lessen the number of  values in the picklist would not be helpful, as the list is that long for a reason. Thanks much!
Hello, and thanks in advance for any responses!

I am trying to return a list of records from another custom object (Values_dreams_Goals) for display on my current custom object (VDG_Display).  The code below has been adapted from another application in the same org that works just fine, but returns the query error below.

System.QueryException: unexpected token: SELECTValues_Dreams_Goals__c 
Class.GoalListExt.getGoalItems: line 25, column 1

My offending class is below.  Line 25 is marked, but I may have an error in the query language itself, since I'm somewhat unfamiliar with it.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class GoalListExt {

    
    public id householdId {get;set;}
    public VDG_Display__c thisDisplay {get;set;}
    
    public list<Values_Dreams_Goals__c> GoalItems;
    public integer QUERY_RECORD_LIMIT = 25;
    
    public GoalListExt() {
   
    }
    
    
    public list<Values_Dreams_Goals__c> getGoalItems()
    {
    
     string parentID = householdId;
     string query = 'SELECT';
     for(Schema.FieldSetMember f : this.getGoalItemsFields())
     {
         query += f.getFieldPath() + ',' ;
     }
     query += 'Id FROM Values_Dreams_Goals__c WHERE Household_linked__c =: parentID limit:QUERY_RECORD_LIMIT';
line 25 -->     GoalItems = (list<Values_Dreams_Goals__c>)  Database.query(query);
     return GoalItems;
     }
    
    public List<Schema.FieldSetMember> getGoalItemsFields() {
        return SObjectType.Values_Dreams_Goals__c.FieldSets.VDGTable.getFields();
    }
}
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Any help would be appreciated.
Thanks in advance.

Nick 
 
Hi Community,

I need a trigger to check a Lead's zip code and determine if it matches a set of zip codes that my business services.  If it is a matching zip code, I would like Salesforce to update a checkbox field called 'Local Delivery'.  This way we can identify which Leads are close to our business.  I believe the pseudo code looks like:

trigger UpdateLocalDelivery on Lead (before insert) {
for (Lead lead : trigger.new){
        // if Lead.zip equals one of the following zip codes [22202, 22203, 22204, 22201]
        // then set Lead.Local_Deliver__c = true;
    }

Thank you in advance!

Also, what would the unit test for this trigger look like?
I have included jQuery as Static Resource and it is working with the Visualforce page when I include my own JavaScript code in <script type="text/javascript"> tag.

However, if I copy/paste the code into a .js file and upload it on static resource and include the file as apex:includeScript value, the JavaScript code never worked.

On the Visualforce page, I wrote jQuery.noConflict(); and use jQuery instead of '$' to make it work.

Later when I copied the original code into a .js file, I did not change anything. It did not work. Then I tried to use something like var j$ = jQuery.noConflict(); and replace all jQuery by j$. Not working. I also tried to delete the noConflict line and all using '$' as selector. Not working. Another try is to add (function($) {  }) (jQuery); to wrap the original code. Still not working.

Is there anything that I am mising to make the external js file which references jQuery working with the visualforce page?
I'm trying to create a function that returns an email.  I want it to return a Salesforce field type Email, like you would put in an sObject, rather than a String.  The reason for this is that true email addresses are case sensitive before the @ and case insensitive after the @.  Here is the header of the function I'd like to change:

    webservice static ???.Email GetMainContactEmail(Id aid) {    <-- replace ??? with library name to qualify Email field type

Here is the test method that does not work because the function is using a String.

    public static testmethod void testGetMainContactEmailOnly() {
        Account testAccount = TestData.MakeAccount();
        Contact testContact = TestData.MakeContact(testAccount);
        System.assertEquals(testContact.Email, Utilities.GetMainContactEmail(testAccount.Id));
    }

The contact is created with a randomly generated mixed case email address consisting of 10 alphanumeric characters, '@', 10 alphanumeric characters, '.com'.  Here is the test result:

System.AssertException: Assertion Failed: Expected: 2BC8reZIC1@S1X422H1ou.com, Actual: 2bc8rezic1@s1x422h1ou.com

If anyone has a reliable alternative to trying to return the field type from the function, something that will still conform to the RFC requirements on case sensitivity, I would like to hear that also.

Thanks for your time and effort. 
I am trying to post a simple text comment to FeedItem. The comment has line breaks.

Following is my code:
 
String comment = 'Test1\r\n\r\nTest2';

String access_token = AuthController.getJIRAOAuthToken();

String authVal = 'OAuth '+access_token;
HttpRequest req = new HttpRequest();
String endpoint = system.label.JIRA_OAuth_SFDC_REST_API_Endpoint+'/services/data/v35.0/chatter/feed-elements/';


System.debug(endpoint); 
req.setEndpoint(endpoint);
req.setMethod('POST');
req.setHeader('Content-Type','application/json; charset=UTF-8');

req.setHeader('Authorization', authVal);




req.setBody('{"body":{"messageSegments":[{"type":"Text","text":"'+comment+'"}]},"feedElementType":"FeedItem","subjectId":"a3gm0000000066S"}');


Http http = new Http();
//System.debug(req);
HTTPResponse res = http.send(req);
System.debug('**'+res);

I am getting below response.
System.HttpResponse[Status=Bad Request, StatusCode=400]

If I am trying the same code without "\r\n" then it works perfectly fine. Any suggestions please ?

I tried replacing "\r\n" with "&nbsp;" as per the rich text feed item https://developer.salesforce.com/docs/atlas.en-us.chatterapi.meta/chatterapi/quickreference_post_feed_element_rich_text.htm but even that didn't help. The comment is posted along with "&nbsp;" in text.
I am asking this question for our Developer, i am an Admin.

We have some code on the account layout that does a calculation on the Assets object.  Serves as a rollup since we cannot directly do a rollup summary.  The code works, the only issue is an Asset must be "touched" in order for the code to do its job.  The question is how can we get the code to run it's calculation without having to manually edit and save an asset?  

Hi,

 

I'd like to have a 'configuration' object in my Force.com app--effectively mirroring the functionality of a properties or a configuration file that you'd have in a non-cloud app.  Conceptually, I could have a singleton object that contains fields that represent the various configuration attributes, modify this object via the standard UI, and read it to access its fields as necessary.

 

However, I'd like to avoid re-reading this object for every request (I know that I can read it once and have it be available via a static variable within the context of the same request).  Is there a way to somehow 'cache' it to make it available for multiple requests without having to re-read this (perhaps only re-reading it every so often)?  Is there a best practice or a Force.com design pattern to accomplish this?  Or is this not even necessary, because the overhead of reading a single object is trivial, due to the DB's own caching?

 

Thanks!

 

Alex