• Tim__m
  • NEWBIE
  • 200 Points
  • Member since 2010

  • Chatter
    Feed
  • 7
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 19
    Questions
  • 29
    Replies

Hey all,

 

Wondering if it's possible to set a picklistEntry as "selected" programmatically. I know usually a user will be doing this, however, I want to do this programmatically because I'm sending an email to salesforce, and the value is already there.

 

Scenario: Send an email to salesforce that will create a custom object. The email will have the field for picklist as well as the picklistEntry.value() in a string format. ie. "Programming Languages: PHP, JS, RoR" I have it splitting up into "Programming Languages" and "PHP" "JS" "RoR".

 

Inside salesforce, there is a multipicklist(multi-select) for Programming Languages, for PHP, JS, RoR and more.

How do I make sure that the custom object field "Programming_Languages" will have PHP, JS, RoR selected and not the other ones?

 

Thanks.

  • November 08, 2010
  • Like
  • 0

Hey everyone,

 

The workhorse for my scheduled counter is giving me DML 101 issues. Anyone know how i can bulkify the following code?

 

 

global class countAgreements implements Database.Batchable<sObject>{
	global final String gstrQuery = 'select ID, Number_of_Agreements__c from Opportunity';
    global Database.QueryLocator start(Database.BatchableContext BC){
		return Database.getQueryLocator(gstrQuery);
    } 
	global void execute(Database.BatchableContext BC, List<sObject> scope){
		List<Opportunity> listOpp = new List<Opportunity>();
		for(SObject objSObject : scope){
			Opportunity objOpportunity = (Opportunity)objSObject;
			Integer intNumberOfAgreements = [SELECT count() FROM echosign_dev1__SIGN_Agreement__c WHERE OpportunityID = :objOpportunity.ID and Is_Type_NDA__c = 1];
			if (intNumberOfAgreements <> objOpportunity.Number_of_Agreements__c){
				objOpportunity.Number_of_Agreements__c = intNumberOfAgreements;
				listOpp.add(objOpportunity);
			}
		if (listOpp.size()>0) {update listOpp;}
		}
	}
	global void finish(Database.BatchableContext BC){
	}
}

 

 

 

any help is greatly appreciated.

  • August 12, 2010
  • Like
  • 0

Okay I've written my code and tested it in my sandbox; works as expected. When I tried to move it to production, I ran a the deployement test and I received the following msg: "Coverage of selected Apex Trigger is 0%...." . Can someone help me write a test class?

 

Below is my Trigger Code:

 

 

trigger CreateTicket on Maintenance_Request__c(after update)

{

    if(Trigger.isUpdate){
        for(Maintenance_Request__c m: Trigger.new)

       {

          if(m.Status__c == 'Pending Support')

          {

               Support_Team_Request__c st = new Support_Team_Request__c();

               //do your stuff, for ex

                  st.Your_name__c = m.Your_Name__c;
                  st.Client_reported_issue__c = 'No';
                   st.Short_description__c = m.Short_Description__c;
                   st.Client_Name__c = m.Client_Name__c;
                   st.Description_of_Issue__c = m.Detailed_Description__c;
                    st.Mailbox__c = m.Mailbox__c;
                    st.Priority__c = 'medium';
                    st.Created_From_MTR__c = 'Yes';
                    st.Request_Type__c = 'production' ;  
                    st.Participant_Name__c = m.Participant_Name__c;
                    st.Participant_ID__c = m.Participant_ID__c;
                    st.CC_Contact__c = m.CC_Contact__c;

                insert st;

          }
         
        }
    }  

}
  • August 11, 2010
  • Like
  • 0

Hi,

 

I've been working on a trigger in which I attempt to convert a date field into a date/time field (with the time being 12:00:00 noon).  However I'm having a hard time getting the formatting correct.

 

The trigger runs on a custom Quote object.

The date field I'm trying to convert is named Required_Date__c.

The new date/time field is named Required_Date_Time__c.

I have also a text field named Test__c, which I use to check the string formatting. 

 

Here is the code snippet:

 

string Rhour = '12';

string Rminute = '00';

string Rsecond = '00';

string Rdate = String.valueOf(c.Required_Date__c) + ' ' + Rhour + ':' + Rminute + ':' + Rsecond;

c.Test__c = Rdate;

c.Required_Date_Time__c = datetime.valueOf(c.Test__c);

 

 

If I comment out the last line of the above snippet, the trigger runs fine and enters the string

2010-03-30 12:00:00

in the Test__c field.

However, when I try to deploy the trigger with the last line included, I get the following error: System.TypeException: Invalid date/time: null 12:00:00

 

I've tried many other things as well, but continue to bang my head against the wall.

 

Any help with this would be greatly appreciated.

 

Thanks!!

Aaron 

 

 

 

Hy!

 

How can I get information about the user profile (System Administrator, standard user, standard platform user) in apex code?

  • March 24, 2010
  • Like
  • 0

This is driving me nuts. I have to click the YES button a billion times when I try to sync with server and apply server to project. Why can't I apply server to project for outbound changes in one simple click? The end goal is to sync the eclipse project with the sandbox then commit to a svn repo. I know what I really need is a CI solution but I don't have time to set that up now. I just want to do it manually for now without clicking a yes button for an hour.

 

Any ideas?

  • December 13, 2011
  • Like
  • 0

Is it possible to make a callout from APEX to a SOAP web service that uses NTLM authentication? If so is there documentation and or samples?

 

I was able to generate an apex class from the WSDL but I don't know how to use it with NTLM auth and I have a funny feeling its not even possible.

 

NTLM authentication is always getting in my way (unless I'm building in .NET) but I have no say in what authentication protocol is used.

  • November 29, 2011
  • Like
  • 0

What happened to the force.com documentation in Eclipse help. There was styling to the content before I upgraded to winter '12. The styling really made the documentation readable. Did a css ref change?

  • November 16, 2011
  • Like
  • 0

Just spent an hour trying to find out why the inlineEditSupport component wasn't updating my picklist field. The bug can be seen with this...

 

<apex:page standardController="Account" recordSetVar="accounts">
	<apex:form >
		<apex:pageBlock >
			<apex:pageBlockButtons >
				<apex:commandButton id="saveButton" action="{!save}" value="Save" />
				<apex:commandButton id="editButton" action="{!edit}" value="Edit" />
				<apex:commandButton id="cancelButton" action="{!cancel}" value="Cancel" />
			</apex:pageBlockButtons>
			<apex:repeat value="{!accounts}" var="acc" rows="20">
				<apex:variable var="isReadOnly" value="{!acc.myCheckboxField__c}" />
				
				<!-- Name field works just as it should no issues here -->
				<apex:outputField value="{!acc.Name}" rendered="{!isReadOnly}"/>
				
				<!-- Display a label or output field based on a apex:variable -->
				<apex:outputLabel value="{!acc.myPicklistField__c}" rendered="{!NOT(isReadOnly)}"/>
				
				<!-- When you dblClick this field you get the picklist and can change the value
				     but the new value is NOT saved to the db. If you look in syslog you can see
				     the new value never gets back to the server, so the bug is on the client? -->
				<apex:outputField value="{!acc.myPicklistField__c}" rendered="{!isReadOnly}"/>
				
				<apex:inlineEditSupport event="ondblClick" showOnEdit="saveButton,cancelButton" hideOnEdit="editButton" />
				<hr/>
			</apex:repeat>
		</apex:pageBlock>
	</apex:form>
</apex:page>



The workaround, don't use an apex:variable in the rendered attribute of the apex:outputField. This works...

 

<apex:page standardController="Account" recordSetVar="accounts">
	<apex:form >
		<apex:pageBlock >
			<apex:pageBlockButtons >
				<apex:commandButton id="saveButton" action="{!save}" value="Save" />
				<apex:commandButton id="editButton" action="{!edit}" value="Edit" />
				<apex:commandButton id="cancelButton" action="{!cancel}" value="Cancel" />
			</apex:pageBlockButtons>
			<apex:repeat value="{!accounts}" var="acc" rows="20">
				
				<apex:outputField value="{!acc.Name}" rendered="{!acc.myCheckboxField__c}"/>
				
				<apex:outputLabel value="{!acc.myPicklistField__c}" rendered="{!NOT(acc.myCheckboxField__c)}"/>
				
				<!-- not using apex:variable works -->
				<apex:outputField value="{!acc.myPicklistField__c}" rendered="{!acc.myCheckboxField__c}"/>
				
				<apex:inlineEditSupport event="ondblClick" showOnEdit="saveButton,cancelButton" hideOnEdit="editButton" />
				<hr/>
			</apex:repeat>
		</apex:pageBlock>
	</apex:form>
</apex:page>

 

This was tested on an api ver. 22.0 visualforce page with Firefox 6.0.2. I did not test on other browsers.

  • October 05, 2011
  • Like
  • 0

At Dreamforce '11 I was told that the Contact-Viewer source was available in two flavors, HTML 5 app and iOS container app (aka hybrid). I'm able to find the source on github for the HTML 5 flavor but not the hybrid flavor.

 

If the hybrid version is out there where can I find it?

  • October 04, 2011
  • Like
  • 0

Hey everyone,

Hope someone can provide input on a unit test issue I'm running into. I have an extension on a custom object that works just fine when you view the VF page but I can't get my unit test to play nice. The error that is thrown when running the unit test is a SObject Exception: You cannot call addFields after you've already loaded the data. The call to addFields is the first thing in my constructor after I set a local property to the constructor arg, see the code snippets...

 

The Extension

public class MyExtension {
    public ApexPages.StandardController stdCtrl { get; set; }

    public MyExtension(ApexPages.StandardController controller) {
        stdCtrl = controller;
        stdCtrl.addFields(new String[] {'field1','field2'});
        ...
    }
}

The Unit Test 

@isTest
private class MyExtensionUnitTest {
    static testMethod void positive_UnitTest() {
        Test.startTest();
        Test.setCurrentPage(Page.MyPage); //a page that uses MyExtension
        system.runAs(testuser) {
            MyCustObj obj = [SELECT foo FROM MyCustObj WHERE id = :theId];
            MyExtension ext = new MyExtension(new ApexPages.StandardController(obj));
            //SObject exception thrown at this point

            //I try this too but same exception.

            MyExtension ext = new MyExtension(new ApexPages.StandardController(new MyCustObj()));
            //SObject exception thrown at this point
           
        }
    }
}

 

I understand the exception that is thrown but I don't know how to test an extension that uses the addFields method of the standard controller. 


Take a look at the following code snippet and tell me what you think, is this a bad idea. I could use describe calls but I might hit the 100 describe call limit. I don't have anyone to bounce ideas off of at the office so I thought some of you would have some good input.

 

/*
obj is a sobject from a dynamic soql call.
fieldName is a string that can be the api name of a field on
obj or the api name of a field on a parent sobject of obj.
(exp. obj could be a Contact record and field name could be
something like: 'Account.Name' or 'myParent__r.myGrandparent__r.myField__c')
*/
private String getFieldValue(Sobject obj, String fieldName) { Object fieldValue; if(fieldName.contains('.')) { for(String s : fieldName.split('\\.')) { try { obj = obj.getSObject(s); } catch(system.SObjectException e) { fieldValue = obj.get(s); } } } else { fieldValue = obj.get(fieldName); } if(fieldValue != null) { if(fieldValue instanceof Datetime) { return getFormatedDatetime( (Datetime) fieldValue); } else if(fieldValue instanceof String) { return (String) fieldValue; } else if ... { ... // and so on } } return null; }

 

How do I work with child relationships in a standard set controller with dynamic visualforce? Here is what I was trying to do. This is not a working example (it throws a system.security.NoAccessException: Object type not accessible. error) but I was hopping I was close to what needs to be done. I know I can write apex to get what I need with the child relationship but I'm trying to use the native power of visualforce. 


 

<<< The Page >>>
<apex:page standardController="myObj__c" extensions="myObjExtension" recordSetvar="myObj">
...
<apex:listViews type="myObj__c">
    <apex:facet name="body">
        <apex:outputPanel>
            <apex:repeat value="{!MySetController.Records}" var="pv">
                <apex:outputLabel value="{!pv['name']}" />
                ...
                <apex:repeat value="{!pv['Relationship__r']}" var="cv">
                    <apex:outputLabel value="{!cv['foo']}" />
                    ...
                </apex:repeat>
            </apex:repeat>
        </apex:outputPanel>
    </apex:facet>
</apex:listViews>
...


<<< The Extension >>>
public class myExtension {

    public ApexPages.StandardSetController mySetController { get; set; }
	
    public myExtension(ApexPages.StandardSetController controller) { 
	mySetController = controller;
	mySetController.addFields(new String[{'name','Relationship__r.foo'});
	...	
    }
}

 

Any thoughts or opinions would help.

 

Am I losing my mind? The snippet below isn't updating my contacts, I don't get any errors or anything it just dosn't update the records. The number of DML rows: 197 out of 10000 is reported and expected. There are no triggers in the org that would get in the way.

 

 

Account a = [select id, name from account where name='New Name'];
List<Contact> cList = [Select id, name, account.name from contact where account.name = 'Old Name'];
for(contact i : cList) {
    i.account = a;
}
update cList;

 

 

  • November 12, 2010
  • Like
  • 0

Using the SingleEmailMessage class I am trying to set the template Id, what Id, and target Id. I was disappointed when I tried to get the html body and found the body to be null. Is there a way to get an email template body after a merge with an sObject? Here is what I thought would work...

 

 

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTargetObjectId(contactId);
mail.setTemplateId(templateId);
mail.setWhatId(caseId);
		
System.debug('*********************');
System.debug(mail.getHtmlBody()); // getHtmlBody returns null :(

 

 

  • November 08, 2010
  • Like
  • 0

This is fun. If you run this block of APEX in the system log everything works without issue...

 

Site mySite = [Select AnalyticsTrackingCode From Site where Name = 'My_Portal' limit 1];
System.debug(mySite.analyticsTrackingCode);

BUT, if you put the same block of APEX in a class and try to save the class you get: Save error: sObject type 'Site' is not supported.

 

What is up with that?

 

  • September 10, 2010
  • Like
  • 0

Are there any tools out there to find all references to an apex class and/or class members? It would be really nice to have a 'Find all references' right click context menu item in the IDE.

  • September 03, 2010
  • Like
  • 0

What is the appropriate value for the accept attribute on the inputFile standard component? I tried "text/plain", "*.txt" and "txt" but none of that works, the browse dialog always shows all files of all types, IE and FireFox.

  • August 05, 2010
  • Like
  • 0

There is lots of good information on developer.force.com about SSO and Salesforce as the service provider but I can't find any information on using Salesforce as the identity provider to another service. I would like to be able to use my salesforce user and contact objects as my identity store for an outside application. Can it be done? Do I have to role my own SAML SSO service within Salesforce to get the job done? What kind of license agreement issues would I have to deal with?

 

Any thoughts?

  • August 02, 2010
  • Like
  • 0

I'm trying to compare two SObjects (Accounts in this example) in a unit test using System.assertEquals, but the assertion fails every time. The SObjects have the same field values so it should come back true, right? Here is the assert exception:

 

 

FATAL_ERROR|System.AssertException: Assertion Failed: Expected: Account:{NumberOfEmployees=10, Name=testAcc0, Description=Test Account, BillingCity=TestCity, BillingPostalCode=90210, BillingStreet=0 main st., Id=001A000000H632WIAR, AnnualRevenue=1000000.55, BillingState=TestState}, Actual: Account:{Name=testAcc0, NumberOfEmployees=10, Description=Test Account, BillingCity=TestCity, BillingPostalCode=90210, BillingStreet=0 main st., Id=001A000000H632WIAR, AnnualRevenue=1000000.55, BillingState=TestState}

 

The only thing I see is the order of the fields but that should not make a difference.

 

How do transactions work with scheduled APEX? If I have a class that schedules an APEX job in a catch block and then rethrow the exception well the APEX job still fire and perform all DML operations within the schedulable class?

 

I was going to build a prototype to test this out but thought I would ask before going crazy with code.

 

Thanks!

Hey all,

 

I have a Force.com site that needs to expose an apex webservice. This webservice needs to be consumed by external resources and the by the Force.com site that exposes it. I'm really trying to stick to SOA here. Note: The Force.com site is public, no username or password needed. So this was simple enough to do until I tried to use SSL. If I set the endpoint of my public webservice to http://myforcedomain.sandboxdev.cs3.force.com/sitename/services/soap/class/myservice I can call the service from outside and from inside BUT if I set the endpoint to https I get the below exception when I try to call the service from inside but not outside...

 

System.CalloutException: IO Exception: java.security.cert.CertificateException: No subject alternative DNS name matching myforcedomain.sandboxdev.cs3.force.com found

 

I have only tested in a sandbox (not dev) and without using custom web address for the force.com site. What would happen if I used a custom web address? I ask because if I can get this all to work it will be going into production where custom web address are used.

 

So my question is, how do i deal with the security certificate issue when calling from inside?  Is it safe to not use SSL when calling a public apex webservice from a public visualforce controller class?

 

 

  • April 30, 2010
  • Like
  • 0
I think I already know the answer to my question, (answer=no), but I'm going to put it out here anyway. Can I validate xml with my xsd in apex? I have an email service that takes in an xml file and I would like to validate the xml using my xsd before I process the inbound email. I know I could just write apex code and use the new dom to read the xml but I would like to avoid writing apex code that checks the schema. The schema can change now and again requiring updates to the xsd. I would like to avoid updating apex code in addition to the xsd. Its a maintenance thing.
Message Edited by Tim__m on 03-24-2010 06:01 AM
  • March 24, 2010
  • Like
  • 0

So I have been asked to rebuild and move everything on our IIS box to Salesforce Sites. Yeah, I know, crazy right. I'm not the decision maker, I'm just the schlep that needs to deliver on the decision makers promises.

 

Anyway, one problem that I don't know how to solve is delivering my JavaScript widgets with Visualforce. Can it be done? Can I do something like this...

 

<apex:page contentType="application/javascript">

Basically I need to prove that I can or can't host my js files on Salesforce in a way that other sites can access them, you know, something like the Google CDN or Yahoo CDN.

 

Any input will be reward with my gratitude.

 

  • February 25, 2010
  • Like
  • 0

Just spent an hour trying to find out why the inlineEditSupport component wasn't updating my picklist field. The bug can be seen with this...

 

<apex:page standardController="Account" recordSetVar="accounts">
	<apex:form >
		<apex:pageBlock >
			<apex:pageBlockButtons >
				<apex:commandButton id="saveButton" action="{!save}" value="Save" />
				<apex:commandButton id="editButton" action="{!edit}" value="Edit" />
				<apex:commandButton id="cancelButton" action="{!cancel}" value="Cancel" />
			</apex:pageBlockButtons>
			<apex:repeat value="{!accounts}" var="acc" rows="20">
				<apex:variable var="isReadOnly" value="{!acc.myCheckboxField__c}" />
				
				<!-- Name field works just as it should no issues here -->
				<apex:outputField value="{!acc.Name}" rendered="{!isReadOnly}"/>
				
				<!-- Display a label or output field based on a apex:variable -->
				<apex:outputLabel value="{!acc.myPicklistField__c}" rendered="{!NOT(isReadOnly)}"/>
				
				<!-- When you dblClick this field you get the picklist and can change the value
				     but the new value is NOT saved to the db. If you look in syslog you can see
				     the new value never gets back to the server, so the bug is on the client? -->
				<apex:outputField value="{!acc.myPicklistField__c}" rendered="{!isReadOnly}"/>
				
				<apex:inlineEditSupport event="ondblClick" showOnEdit="saveButton,cancelButton" hideOnEdit="editButton" />
				<hr/>
			</apex:repeat>
		</apex:pageBlock>
	</apex:form>
</apex:page>



The workaround, don't use an apex:variable in the rendered attribute of the apex:outputField. This works...

 

<apex:page standardController="Account" recordSetVar="accounts">
	<apex:form >
		<apex:pageBlock >
			<apex:pageBlockButtons >
				<apex:commandButton id="saveButton" action="{!save}" value="Save" />
				<apex:commandButton id="editButton" action="{!edit}" value="Edit" />
				<apex:commandButton id="cancelButton" action="{!cancel}" value="Cancel" />
			</apex:pageBlockButtons>
			<apex:repeat value="{!accounts}" var="acc" rows="20">
				
				<apex:outputField value="{!acc.Name}" rendered="{!acc.myCheckboxField__c}"/>
				
				<apex:outputLabel value="{!acc.myPicklistField__c}" rendered="{!NOT(acc.myCheckboxField__c)}"/>
				
				<!-- not using apex:variable works -->
				<apex:outputField value="{!acc.myPicklistField__c}" rendered="{!acc.myCheckboxField__c}"/>
				
				<apex:inlineEditSupport event="ondblClick" showOnEdit="saveButton,cancelButton" hideOnEdit="editButton" />
				<hr/>
			</apex:repeat>
		</apex:pageBlock>
	</apex:form>
</apex:page>

 

This was tested on an api ver. 22.0 visualforce page with Firefox 6.0.2. I did not test on other browsers.

  • October 05, 2011
  • Like
  • 0

At Dreamforce '11 I was told that the Contact-Viewer source was available in two flavors, HTML 5 app and iOS container app (aka hybrid). I'm able to find the source on github for the HTML 5 flavor but not the hybrid flavor.

 

If the hybrid version is out there where can I find it?

  • October 04, 2011
  • Like
  • 0

Does anyone know if there is a new release coming up for IDE? Are there alternatives for force.com ide? 

  • September 28, 2011
  • Like
  • 0

I was curious to know if there is a best practice for designing unit tests that can handle the addition of new required fields to an object. For example, let's say that I have an insert trigger defined on a opportunity object.  so, in order to get complete code coverage I develop a test method which creates a dummy opportunity record. At the time of writing this test method I make sure that the dummy record has all the necessary fields included.  the dummy record is inserted and causes the insert trigger to fire and everything works fine. Let's say six months later a new field is added to the opportunity object and it is a required field. Would that not cause my test method to be invalid?

 

Just curious if anyone out there has experienced this issue in the past and what technique you used to deal with this circumstance.

 

~Tyler

Hey everyone,

Hope someone can provide input on a unit test issue I'm running into. I have an extension on a custom object that works just fine when you view the VF page but I can't get my unit test to play nice. The error that is thrown when running the unit test is a SObject Exception: You cannot call addFields after you've already loaded the data. The call to addFields is the first thing in my constructor after I set a local property to the constructor arg, see the code snippets...

 

The Extension

public class MyExtension {
    public ApexPages.StandardController stdCtrl { get; set; }

    public MyExtension(ApexPages.StandardController controller) {
        stdCtrl = controller;
        stdCtrl.addFields(new String[] {'field1','field2'});
        ...
    }
}

The Unit Test 

@isTest
private class MyExtensionUnitTest {
    static testMethod void positive_UnitTest() {
        Test.startTest();
        Test.setCurrentPage(Page.MyPage); //a page that uses MyExtension
        system.runAs(testuser) {
            MyCustObj obj = [SELECT foo FROM MyCustObj WHERE id = :theId];
            MyExtension ext = new MyExtension(new ApexPages.StandardController(obj));
            //SObject exception thrown at this point

            //I try this too but same exception.

            MyExtension ext = new MyExtension(new ApexPages.StandardController(new MyCustObj()));
            //SObject exception thrown at this point
           
        }
    }
}

 

I understand the exception that is thrown but I don't know how to test an extension that uses the addFields method of the standard controller. 


How do I work with child relationships in a standard set controller with dynamic visualforce? Here is what I was trying to do. This is not a working example (it throws a system.security.NoAccessException: Object type not accessible. error) but I was hopping I was close to what needs to be done. I know I can write apex to get what I need with the child relationship but I'm trying to use the native power of visualforce. 


 

<<< The Page >>>
<apex:page standardController="myObj__c" extensions="myObjExtension" recordSetvar="myObj">
...
<apex:listViews type="myObj__c">
    <apex:facet name="body">
        <apex:outputPanel>
            <apex:repeat value="{!MySetController.Records}" var="pv">
                <apex:outputLabel value="{!pv['name']}" />
                ...
                <apex:repeat value="{!pv['Relationship__r']}" var="cv">
                    <apex:outputLabel value="{!cv['foo']}" />
                    ...
                </apex:repeat>
            </apex:repeat>
        </apex:outputPanel>
    </apex:facet>
</apex:listViews>
...


<<< The Extension >>>
public class myExtension {

    public ApexPages.StandardSetController mySetController { get; set; }
	
    public myExtension(ApexPages.StandardSetController controller) { 
	mySetController = controller;
	mySetController.addFields(new String[{'name','Relationship__r.foo'});
	...	
    }
}

 

Any thoughts or opinions would help.

 

Am I losing my mind? The snippet below isn't updating my contacts, I don't get any errors or anything it just dosn't update the records. The number of DML rows: 197 out of 10000 is reported and expected. There are no triggers in the org that would get in the way.

 

 

Account a = [select id, name from account where name='New Name'];
List<Contact> cList = [Select id, name, account.name from contact where account.name = 'Old Name'];
for(contact i : cList) {
    i.account = a;
}
update cList;

 

 

  • November 12, 2010
  • Like
  • 0

Using the SingleEmailMessage class I am trying to set the template Id, what Id, and target Id. I was disappointed when I tried to get the html body and found the body to be null. Is there a way to get an email template body after a merge with an sObject? Here is what I thought would work...

 

 

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTargetObjectId(contactId);
mail.setTemplateId(templateId);
mail.setWhatId(caseId);
		
System.debug('*********************');
System.debug(mail.getHtmlBody()); // getHtmlBody returns null :(

 

 

  • November 08, 2010
  • Like
  • 0

Hey all,

 

Wondering if it's possible to set a picklistEntry as "selected" programmatically. I know usually a user will be doing this, however, I want to do this programmatically because I'm sending an email to salesforce, and the value is already there.

 

Scenario: Send an email to salesforce that will create a custom object. The email will have the field for picklist as well as the picklistEntry.value() in a string format. ie. "Programming Languages: PHP, JS, RoR" I have it splitting up into "Programming Languages" and "PHP" "JS" "RoR".

 

Inside salesforce, there is a multipicklist(multi-select) for Programming Languages, for PHP, JS, RoR and more.

How do I make sure that the custom object field "Programming_Languages" will have PHP, JS, RoR selected and not the other ones?

 

Thanks.

  • November 08, 2010
  • Like
  • 0

This is fun. If you run this block of APEX in the system log everything works without issue...

 

Site mySite = [Select AnalyticsTrackingCode From Site where Name = 'My_Portal' limit 1];
System.debug(mySite.analyticsTrackingCode);

BUT, if you put the same block of APEX in a class and try to save the class you get: Save error: sObject type 'Site' is not supported.

 

What is up with that?

 

  • September 10, 2010
  • Like
  • 0

Are there any tools out there to find all references to an apex class and/or class members? It would be really nice to have a 'Find all references' right click context menu item in the IDE.

  • September 03, 2010
  • Like
  • 0

Hey everyone,

 

The workhorse for my scheduled counter is giving me DML 101 issues. Anyone know how i can bulkify the following code?

 

 

global class countAgreements implements Database.Batchable<sObject>{
	global final String gstrQuery = 'select ID, Number_of_Agreements__c from Opportunity';
    global Database.QueryLocator start(Database.BatchableContext BC){
		return Database.getQueryLocator(gstrQuery);
    } 
	global void execute(Database.BatchableContext BC, List<sObject> scope){
		List<Opportunity> listOpp = new List<Opportunity>();
		for(SObject objSObject : scope){
			Opportunity objOpportunity = (Opportunity)objSObject;
			Integer intNumberOfAgreements = [SELECT count() FROM echosign_dev1__SIGN_Agreement__c WHERE OpportunityID = :objOpportunity.ID and Is_Type_NDA__c = 1];
			if (intNumberOfAgreements <> objOpportunity.Number_of_Agreements__c){
				objOpportunity.Number_of_Agreements__c = intNumberOfAgreements;
				listOpp.add(objOpportunity);
			}
		if (listOpp.size()>0) {update listOpp;}
		}
	}
	global void finish(Database.BatchableContext BC){
	}
}

 

 

 

any help is greatly appreciated.

  • August 12, 2010
  • Like
  • 0

i am having trouble finding examples to test something like this...

 

	 	if ( searchStr.length() < 2 ) {
	 		ApexPages.addMessage( new ApexPages.Message(
	 			ApexPages.Severity.INFO, 'Search requires more characters'));
	 		return null;
	 	}

 

thank you.

Okay I've written my code and tested it in my sandbox; works as expected. When I tried to move it to production, I ran a the deployement test and I received the following msg: "Coverage of selected Apex Trigger is 0%...." . Can someone help me write a test class?

 

Below is my Trigger Code:

 

 

trigger CreateTicket on Maintenance_Request__c(after update)

{

    if(Trigger.isUpdate){
        for(Maintenance_Request__c m: Trigger.new)

       {

          if(m.Status__c == 'Pending Support')

          {

               Support_Team_Request__c st = new Support_Team_Request__c();

               //do your stuff, for ex

                  st.Your_name__c = m.Your_Name__c;
                  st.Client_reported_issue__c = 'No';
                   st.Short_description__c = m.Short_Description__c;
                   st.Client_Name__c = m.Client_Name__c;
                   st.Description_of_Issue__c = m.Detailed_Description__c;
                    st.Mailbox__c = m.Mailbox__c;
                    st.Priority__c = 'medium';
                    st.Created_From_MTR__c = 'Yes';
                    st.Request_Type__c = 'production' ;  
                    st.Participant_Name__c = m.Participant_Name__c;
                    st.Participant_ID__c = m.Participant_ID__c;
                    st.CC_Contact__c = m.CC_Contact__c;

                insert st;

          }
         
        }
    }  

}
  • August 11, 2010
  • Like
  • 0

I developed to 2 custom VF Pages with associated custom tabs. The first VF page used a commandLink to navigate to the second VF with using a PageReference in a CustomController. Like so

 

 

<apex:commandLink action="{!SearchPage}" id="SearchLink">Do Search</apex:commandLink> <br/>

 

 

All good, the 2nd Page opened fine, EXCEPT that the Tab associated with the find page wasn't selected, instead the first tab was selected. Put more accurately the CSS wasn't updating to reflect the currently selected page. The target VF page in question isn't associated with an SObject (haven't tested this so I'm not sure if this is relevant). In this instance its a custom SearchPage

 

Ok what to do - I couldn't find any documentation or help, but I realised that the issue actually lay with the CSS... If I could manipulate the CSS I could fix the issue - step forward jQuery. I needed to change the CSS in the DOM and jQuery is just the tool.

 

**** WARNING***** this is a hack, if SFDC change the CSS or structure this code could break.

 

First setup you reference to the jQuery Lib in your target VF page

 

 

<script type="text/javascript"  src="{!URLFOR($Resource.jQuery, '/jquery-1.4.2.min.js')}"></script>

 

 

The tabs on the standard interface are wrapped in a table with the class name '.tab'

 

 

<table cellspacing="0" cellpadding="0" border="0" id="tabBar" class="tab"><tbody>
<tr>
<td nowrap="nowrap">
<div>
<a title="Home Tab" href="https://na7.salesforce.com/home/home.jsp">Home</a>
</div>
</td>

 

 

The td element of the currently selected tab will have a class added with the values like so:

 

 

<td nowrap="nowrap" class="currentTab primaryPalette">

 

 

So what we need to do is remove the class from the incorrectly highlighted tab and add it to the tab we want highlighted. Here is the jQuery to do this. (My jQuery skills aren't going to win any prizes, someone may have a shorter/better way of achieving this)

 

 

<script type="text/javascript">
j$ = jQuery.noConflict();
	
	j$(document).ready(function($) {
	
		var title = j$('.tab').find('.currentTab > div > a').attr('title');
		
		if (title != 'Search Tab - Selected') {
			j$('.tab').find('.currentTab').removeClass('currentTab primaryPalette');
			
			var x= j$('a[title|=Search Tab]').attr('title', 'Search Tab - Selected');
			
			j$(x).parent().parent().addClass('currentTab primaryPalette');
		}
	});

</script>

 The title of the a link of the seleted tab is always myTabName Tab, if its currently selected is myTabName Tab -Selected. The code basically removes the class from the incorrect tab and adds it to the one we want.

 

The double use of .parent() (please feel free to offer a better technique) navigates from the <a> through the <div> back the current <td>, this is where the class needs to be added. And it works!!! But its a hack

 

 

 

 

 

 

 

 

Hey all,

 

I have a Force.com site that needs to expose an apex webservice. This webservice needs to be consumed by external resources and the by the Force.com site that exposes it. I'm really trying to stick to SOA here. Note: The Force.com site is public, no username or password needed. So this was simple enough to do until I tried to use SSL. If I set the endpoint of my public webservice to http://myforcedomain.sandboxdev.cs3.force.com/sitename/services/soap/class/myservice I can call the service from outside and from inside BUT if I set the endpoint to https I get the below exception when I try to call the service from inside but not outside...

 

System.CalloutException: IO Exception: java.security.cert.CertificateException: No subject alternative DNS name matching myforcedomain.sandboxdev.cs3.force.com found

 

I have only tested in a sandbox (not dev) and without using custom web address for the force.com site. What would happen if I used a custom web address? I ask because if I can get this all to work it will be going into production where custom web address are used.

 

So my question is, how do i deal with the security certificate issue when calling from inside?  Is it safe to not use SSL when calling a public apex webservice from a public visualforce controller class?

 

 

  • April 30, 2010
  • Like
  • 0