• Jeff C.ax327
  • NEWBIE
  • 10 Points
  • Member since 2007

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 23
    Replies

I've managed to write code that inserts a value into a picklist field from my c# web application.  However, it is VERY clunky and I still can't figure out how to keep from losing some of the field properties.

 

First, it seems a little silly to have to programmatically recreate the entire picklist field just so I can update it with one new value in the picklistValues property.  Also, I have to do a describeSObject and then step through all the fields looking for the right field name.  Isn't there a way to just grab the metadata for a field directly?  I've seen code like the following, but....

Schema.DescribeFieldResult f = Schema.sObjectType.Account.fields.MyFieldName__c;

 ...but, I don't seem to have the Schema namespace/library at my disposal from the C# environment.  Is there ANY way to get DescribeFieldResult functionality in C#?

 

So I loop through the fields in the object, find the one I want, step through each of the picklist values and recreate them in a new array.  Then I add my new entry to the picklist values array and save it to the picklistValues property.  I can update the field and the new value does in fact show up in Salesforce.... but...

 

...another problem is that I end up losing the Picklist.Description and Picklist.Sorted properties because the Field object that I'm reading from doesn't have that information.

Well, enough words from me, here is the code.  This works, but you lose the Description and Sorted settings each time.  I post it in hopes that it helps someone and that perhaps someone can help us figure out the rest.

 

 

public void InsertPicklistValue(string objectName, string picklistFieldName, string valueToInsert) { try { // Load describe info for the object. DescribeSObjectResult descSObjectRslt = c_sfEnterprise.describeSObject(objectName); if (descSObjectRslt != null) { Field[] fields = descSObjectRslt.fields; foreach (Field field in fields) { if (field.name == picklistFieldName) { // Get the array of existing picklist entries. PicklistEntry[] picklistEntries = field.picklistValues; // We have to recreate the entire list of existing picklist values... List<PicklistValue> pVals = new List<PicklistValue>(); PicklistValue pVal; foreach (PicklistEntry picklistEntry in picklistEntries) { pVal = new PicklistValue(); pVal.@default = picklistEntry.defaultValue; if (picklistEntry.label != null) pVal.fullName = picklistEntry.label; else pVal.fullName = picklistEntry.value; pVals.Add(pVal); } // Add the NEW value... pVal = new PicklistValue(); pVal.fullName = valueToInsert; pVals.Add(pVal); // Now that we have the values, we need to save them to a new picklist. Picklist pList = new Picklist(); pList.picklistValues = pVals.ToArray(); //pList.sorted = how can we get this from the existing field? CustomField picklistField = new CustomField(); picklistField.fullName = objectName + "." + picklistFieldName; picklistField.label = field.label; picklistField.type = FieldType.Picklist; picklistField.picklist = pList; picklistField.inlineHelpText = field.inlineHelpText; //picklistField.description = how/where can we get this? // Update the existing picklist. UpdateMetadata updatedMetadata = new UpdateMetadata(); updatedMetadata.currentName = objectName + "." + picklistFieldName; updatedMetadata.metadata = picklistField; AsyncResult result = update(new UpdateMetadata[] { updatedMetadata })[0]; while (!result.done) { System.Threading.Thread.Sleep(result.secondsToWait * 1000); result = checkStatus(new string[] { result.id })[0]; } if (result.state == AsyncRequestState.Error) Console.WriteLine("Error {0}\n{1}", result.statusCode, result.message); else Console.WriteLine("Picklist updated successfully"); break; } } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("\nFailed to get " + objectName + " description, error message was: \n " + ex); } }

 

 

Anyone?  Bueller?

 

 

 

We need the ability to programmatically add new picklist values from our website to a Salesforce object.

I am new to the Metadata API, but it sure looks like that's the way to do it.

So I downloaded and added the Metadata API web service to my c#.net application.

 

There is plenty of sample code that demonstrates how to get up and running.

I even found sample code on how to modify picklists.

However, none of the "set" methods are available in the library and they are flagged as unrecognized.

Below, all references in red font are syntax errors and the methods cannot be resolved.

 

static void CreatePicklist() { Picklist expenseStatus = new Picklist(); PicklistValue unsubmitted = new PicklistValue(); unsubmitted.setFullName("Unsubmitted"); PicklistValue submitted = new PicklistValue(); submitted.setFullName("Submitted"); expenseStatus.setPicklistValues(new PicklistValue[] {unsubmitted, submitted}); CustomField expenseStatusField = new CustomField(); expenseStatusField.setFullName("ExpenseReport__c.ExpenseStatus__c"); expenseStatusField.setLabel("Expense Report Status"); expenseStatusField.setType(FieldType.Picklist); expenseStatusField.setPicklist(expenseStatus); metaService.create(new Metadata[] { expenseStatusField }); }

 

 

I downloaded the Metadata API from an administrator-privileged account on both production and sandbox instances, but nothing helps.  Any advice would be most appreciated.


Thanks!

 

We have a custom object that maintains a one-to-one relationship with the Contact object for contacts of a certain RecordType.  For these special contacts, we want to display the related custom object record as another detail section right below the Contact detail section.  We do not want to override the Contact page for all contacts, just for this one record type.  Unfortunately, there is no way to override View/Edit/etc for a specific record type, but Winter '09 does give us the ability to embed a Visualforce page within a page section on a standard page layout.  So, I created a page layout for our special record type and got busy...
 
Unfortunately, there is no way to make the page section expand to accomodate the contents -- you can give 100% width, but you have to provide a static height in pixels...... but that's another story, and not my current problem.
 
The problem is that, while the embedded custom detail section displays okay in View mode, when you click the embedded Edit button, another copy of the Salesforce header and sidebar are displayed in the page section, so you now have nested headers and sidebars.  Ah, but you immediately think you can get around this by replacing the custom object's default Edit button with a custom one that turns off the header and sidebar... no dice.  In fact, in this case if you don't turn off the header and sidebar you end up with an additional nest resulting in a total of three headers and sidebars.
 
Then I tried overriding the custom object's Edit with a simple Visualforce page that turns off the header and sidebar... but the page comes up in View mode unless you populate the <apex: page action="{!edit}"> attribute.  What *this* does is put you in an endless loop of calling the VF page and placing it in Edit mode over and over.
 
Tried every combination I can think of.  Doesn't play nice.  Does anyone know how to embed a Visualforce page in a page layout section that allows Edit without the extra header and sidebar?
 
Or even better, is there in fact a way to override View/Edit for a certain record type?  Then I could totally customize my page without all this fixed-height-embedding crap. :-)
I need to create a button that launches a new url in a separate window.  I need to do some custom coding to properly build the url, i.e., I need to query a couple objects and build the URL from the values returned.  The standard merge fields won't work because the other objects I need info from are not in scope.  Is there any way to call an APEX method as a merge field?
 
Like this?
{! myApexClass.getSpecialUrl( Contact.Id ) }
 
Or... is there a different way I can accomplish this?  I'd rather not use client-side javascript because I don't want to hard-code the window open properties.
 
I have a custom object with a 1-to-1 relationship with the Contact object via a lookup field.  I want to create a Visualforce page that shows the Contact detail section on top and the customObj__c detail section below it.  I know that I could work around it by using the Contact standard controller for the page and then lay out my custom object's fields by hand, but it would be fantastic if it were possible to do this using standard controllers for both, since that would allow the page layout tool to be used (and different layouts per record type, etc).
 
I'm still pretty new to Visualforce and custom controllers, extensions, and components.  I thought maybe I could get this to work by putting an <apex:detail> section in a custom component.  The first problem is that it appears there's no way to have a component use a standard controller.  Secondly, when the component is included in the main Contact page, the <apex:detail> section takes on the scope of the Contact record, rather than pull from the controller of the component.
 
I guess I'm essentially trying to put together a sort of "Console" type of functionality where multiple detail sections are present and they relate to the main Contact record.  Is this possible using Visualforce?
 
Thanks,
Jeff
 
We have several RecordTypes for our Contacts.  For our "Study Contact" page layout, all the appropriate detail fields are there, and we have a related list that shows Contacts that the current Contact has referred to us.  I want to hide the default New button on this related list and replace it with a "New Referral" button.  Clicking the "New Referral" button should invoke the New action, but set the RecordType to "Study Contact" behind the scenes and bypass the "Select Contact Record Type" page.
 
I have looked everywhere for examples, and managed to put together the following... but it still shows the "Select Contact Record Type" page.   I am putting the RecordType parameter in the parameter array and also including it directly on the URL just in case....  Help?
 
Code:
//First construct the new URL
var newUrl = "{!URLFOR( $Action.Contact.NewContact, null,
[RecordType=Contact.RecordType,
CF00N70000002GKJz_lkid=Contact.Id,
con4_lkid=Account.Id,
retURL=$Request.retURL], true)}&RecordType={!Contact.RecordType}";
//Then redirect the user to it
window.parent.location.replace(newUrl);

This is run in an Execute Javascript button.
I have tried putting the RecordTypeId value in there directly too (rather than use Contact.RecordType), but to no avail.
I'm also trying to automatically link the new Contact with the referrer Contact, and trying to pre-populate the Account ID.
 
Thank you for your help,
Jeff

 
When I try to save a datetime value to Salesforce through the Enterprise API (SforceEnterprise), 4 hours gets subtracted from the time.  When I retrieve a datetime value from Salesforce through the API, 4 hours gets added to the time.  (my timezone is EST)
 
It seems obvious that this is a timezone issue, and I have tried the following to no avail:
    mySalesforceObject.MyDatetimeField__c = new DateTime(dtmOrigDateTime, DateTimeKind.Utc);
 
I figured that by specifying that it is a UTC datetime, that would fix it, but it doesn't.
All I want is for the time to be saved and retrieved as is, with no subtraction or addition of hours.
 
Is there a setting on the sforceService object somewhere or on the SObject that can correct this behavior?
 
Thank you for your help, this is driving me nuts.
 
 
Jeff
I have tried using the simple example of building a listener in the Outbound Messaging section of the API developer doc.  But I must be truly missing something.  Is there a more thorough example somewhere?
 
I have successfully downloaded and used the Enterprise and Partner WSDL interfaces to update SalesForce objects from my web app, but when I try to include a listener to accept SalesForce Outbound Messaging calls, things don't seem to jive.
 
There seem to be some typos in the Building a Listener section, because my code doesn't find an INotificationBinding object to implement, and other file and class names earlier in the text are inconsistent.
 
Also, I don't see how this listener accepts and processes my particular outbound message.  Where and how do I access the information in the message? (parameter values, etc.)
 
Also, when I specify the endpoint in SalesForce, do I just point to my server and the virtual directory of my application, or do I include the name of the web service too?
 
Obviously I am quite new at this and could really use more detailed info.  Any help is greatly appreciated.
 
(Using ASP.net 2.0 and C# and SalesForce Unlimited)
 

I've managed to write code that inserts a value into a picklist field from my c# web application.  However, it is VERY clunky and I still can't figure out how to keep from losing some of the field properties.

 

First, it seems a little silly to have to programmatically recreate the entire picklist field just so I can update it with one new value in the picklistValues property.  Also, I have to do a describeSObject and then step through all the fields looking for the right field name.  Isn't there a way to just grab the metadata for a field directly?  I've seen code like the following, but....

Schema.DescribeFieldResult f = Schema.sObjectType.Account.fields.MyFieldName__c;

 ...but, I don't seem to have the Schema namespace/library at my disposal from the C# environment.  Is there ANY way to get DescribeFieldResult functionality in C#?

 

So I loop through the fields in the object, find the one I want, step through each of the picklist values and recreate them in a new array.  Then I add my new entry to the picklist values array and save it to the picklistValues property.  I can update the field and the new value does in fact show up in Salesforce.... but...

 

...another problem is that I end up losing the Picklist.Description and Picklist.Sorted properties because the Field object that I'm reading from doesn't have that information.

Well, enough words from me, here is the code.  This works, but you lose the Description and Sorted settings each time.  I post it in hopes that it helps someone and that perhaps someone can help us figure out the rest.

 

 

public void InsertPicklistValue(string objectName, string picklistFieldName, string valueToInsert) { try { // Load describe info for the object. DescribeSObjectResult descSObjectRslt = c_sfEnterprise.describeSObject(objectName); if (descSObjectRslt != null) { Field[] fields = descSObjectRslt.fields; foreach (Field field in fields) { if (field.name == picklistFieldName) { // Get the array of existing picklist entries. PicklistEntry[] picklistEntries = field.picklistValues; // We have to recreate the entire list of existing picklist values... List<PicklistValue> pVals = new List<PicklistValue>(); PicklistValue pVal; foreach (PicklistEntry picklistEntry in picklistEntries) { pVal = new PicklistValue(); pVal.@default = picklistEntry.defaultValue; if (picklistEntry.label != null) pVal.fullName = picklistEntry.label; else pVal.fullName = picklistEntry.value; pVals.Add(pVal); } // Add the NEW value... pVal = new PicklistValue(); pVal.fullName = valueToInsert; pVals.Add(pVal); // Now that we have the values, we need to save them to a new picklist. Picklist pList = new Picklist(); pList.picklistValues = pVals.ToArray(); //pList.sorted = how can we get this from the existing field? CustomField picklistField = new CustomField(); picklistField.fullName = objectName + "." + picklistFieldName; picklistField.label = field.label; picklistField.type = FieldType.Picklist; picklistField.picklist = pList; picklistField.inlineHelpText = field.inlineHelpText; //picklistField.description = how/where can we get this? // Update the existing picklist. UpdateMetadata updatedMetadata = new UpdateMetadata(); updatedMetadata.currentName = objectName + "." + picklistFieldName; updatedMetadata.metadata = picklistField; AsyncResult result = update(new UpdateMetadata[] { updatedMetadata })[0]; while (!result.done) { System.Threading.Thread.Sleep(result.secondsToWait * 1000); result = checkStatus(new string[] { result.id })[0]; } if (result.state == AsyncRequestState.Error) Console.WriteLine("Error {0}\n{1}", result.statusCode, result.message); else Console.WriteLine("Picklist updated successfully"); break; } } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("\nFailed to get " + objectName + " description, error message was: \n " + ex); } }

 

 

Anyone?  Bueller?

 

 

 

We need the ability to programmatically add new picklist values from our website to a Salesforce object.

I am new to the Metadata API, but it sure looks like that's the way to do it.

So I downloaded and added the Metadata API web service to my c#.net application.

 

There is plenty of sample code that demonstrates how to get up and running.

I even found sample code on how to modify picklists.

However, none of the "set" methods are available in the library and they are flagged as unrecognized.

Below, all references in red font are syntax errors and the methods cannot be resolved.

 

static void CreatePicklist() { Picklist expenseStatus = new Picklist(); PicklistValue unsubmitted = new PicklistValue(); unsubmitted.setFullName("Unsubmitted"); PicklistValue submitted = new PicklistValue(); submitted.setFullName("Submitted"); expenseStatus.setPicklistValues(new PicklistValue[] {unsubmitted, submitted}); CustomField expenseStatusField = new CustomField(); expenseStatusField.setFullName("ExpenseReport__c.ExpenseStatus__c"); expenseStatusField.setLabel("Expense Report Status"); expenseStatusField.setType(FieldType.Picklist); expenseStatusField.setPicklist(expenseStatus); metaService.create(new Metadata[] { expenseStatusField }); }

 

 

I downloaded the Metadata API from an administrator-privileged account on both production and sandbox instances, but nothing helps.  Any advice would be most appreciated.


Thanks!

 

Hi,

does anyone know if it's possible to rollup case fields to an account field? For example if I wanted to have a field that displayed the number of cases an account had filed. My organization has person account enabled. It doesn't appear to be possible but I though I'd ask just incase I'm missing something.

Thanks for any help! :)
We have a custom object that maintains a one-to-one relationship with the Contact object for contacts of a certain RecordType.  For these special contacts, we want to display the related custom object record as another detail section right below the Contact detail section.  We do not want to override the Contact page for all contacts, just for this one record type.  Unfortunately, there is no way to override View/Edit/etc for a specific record type, but Winter '09 does give us the ability to embed a Visualforce page within a page section on a standard page layout.  So, I created a page layout for our special record type and got busy...
 
Unfortunately, there is no way to make the page section expand to accomodate the contents -- you can give 100% width, but you have to provide a static height in pixels...... but that's another story, and not my current problem.
 
The problem is that, while the embedded custom detail section displays okay in View mode, when you click the embedded Edit button, another copy of the Salesforce header and sidebar are displayed in the page section, so you now have nested headers and sidebars.  Ah, but you immediately think you can get around this by replacing the custom object's default Edit button with a custom one that turns off the header and sidebar... no dice.  In fact, in this case if you don't turn off the header and sidebar you end up with an additional nest resulting in a total of three headers and sidebars.
 
Then I tried overriding the custom object's Edit with a simple Visualforce page that turns off the header and sidebar... but the page comes up in View mode unless you populate the <apex: page action="{!edit}"> attribute.  What *this* does is put you in an endless loop of calling the VF page and placing it in Edit mode over and over.
 
Tried every combination I can think of.  Doesn't play nice.  Does anyone know how to embed a Visualforce page in a page layout section that allows Edit without the extra header and sidebar?
 
Or even better, is there in fact a way to override View/Edit for a certain record type?  Then I could totally customize my page without all this fixed-height-embedding crap. :-)
I need to create a button that launches a new url in a separate window.  I need to do some custom coding to properly build the url, i.e., I need to query a couple objects and build the URL from the values returned.  The standard merge fields won't work because the other objects I need info from are not in scope.  Is there any way to call an APEX method as a merge field?
 
Like this?
{! myApexClass.getSpecialUrl( Contact.Id ) }
 
Or... is there a different way I can accomplish this?  I'd rather not use client-side javascript because I don't want to hard-code the window open properties.
 
Hi,
 
I worte below apext triiger but have no idea how to write test case for this tigger. I tried to search around but didn't get idea..
 
Code:
trigger createRateIncreaseChange on Account (before update) {

    List<Rate_Increase_Tracker__c> rateIncrease = new List<Rate_Increase_Tracker__c>();
    
    for (Integer i = 0; i < Trigger.new.size(); i++) {
     
     if ( (Trigger.old[i].Ad_Package_Order_Activated_Date__c != Trigger.new[i].Ad_Package_Order_Activated_Date__c)) {

            rateIncrease.add(new Rate_Increase_Tracker__c(New_Contract_Term__c = '1', Account__c = Trigger.old[i].id));
           
        }
   
     }
     
     insert rateIncrease;
     
}

 
Thanks,
  • September 22, 2008
  • Like
  • 0
I have a custom object with a 1-to-1 relationship with the Contact object via a lookup field.  I want to create a Visualforce page that shows the Contact detail section on top and the customObj__c detail section below it.  I know that I could work around it by using the Contact standard controller for the page and then lay out my custom object's fields by hand, but it would be fantastic if it were possible to do this using standard controllers for both, since that would allow the page layout tool to be used (and different layouts per record type, etc).
 
I'm still pretty new to Visualforce and custom controllers, extensions, and components.  I thought maybe I could get this to work by putting an <apex:detail> section in a custom component.  The first problem is that it appears there's no way to have a component use a standard controller.  Secondly, when the component is included in the main Contact page, the <apex:detail> section takes on the scope of the Contact record, rather than pull from the controller of the component.
 
I guess I'm essentially trying to put together a sort of "Console" type of functionality where multiple detail sections are present and they relate to the main Contact record.  Is this possible using Visualforce?
 
Thanks,
Jeff
 
We have several RecordTypes for our Contacts.  For our "Study Contact" page layout, all the appropriate detail fields are there, and we have a related list that shows Contacts that the current Contact has referred to us.  I want to hide the default New button on this related list and replace it with a "New Referral" button.  Clicking the "New Referral" button should invoke the New action, but set the RecordType to "Study Contact" behind the scenes and bypass the "Select Contact Record Type" page.
 
I have looked everywhere for examples, and managed to put together the following... but it still shows the "Select Contact Record Type" page.   I am putting the RecordType parameter in the parameter array and also including it directly on the URL just in case....  Help?
 
Code:
//First construct the new URL
var newUrl = "{!URLFOR( $Action.Contact.NewContact, null,
[RecordType=Contact.RecordType,
CF00N70000002GKJz_lkid=Contact.Id,
con4_lkid=Account.Id,
retURL=$Request.retURL], true)}&RecordType={!Contact.RecordType}";
//Then redirect the user to it
window.parent.location.replace(newUrl);

This is run in an Execute Javascript button.
I have tried putting the RecordTypeId value in there directly too (rather than use Contact.RecordType), but to no avail.
I'm also trying to automatically link the new Contact with the referrer Contact, and trying to pre-populate the Account ID.
 
Thank you for your help,
Jeff

 
Hello,

I'm a relatively experienced developer, but am new to salesforce.  A client has asked us to put together an application to demo some things for them.  I've been able to do what I want to do so far, but I've been having a number of headaches with salesforce in general.

My first issue was that building things (Objects, Tabs, Apps, etc) with the web-interface, while functional, was way too slow to do things on the scale I want to do them.  This is understandable -- it's a web interface, and it needs to be usable by users at every point along the experience spectrum.

I looked around for a more "heavyweight" solution for developing Salesforce stuff and found the Force IDE plugin for Eclipse (distributed on this website).   I've got that up and running, and while it works, I seem to keep hitting weird annoying glitches. 

My most recent frustration is the IDE's weird tendency to revert all the changes I made to an object if it fails validation -- I'll hit Alt+F S to save, it will churn for a bit, throw an error in the "Problems" tab and then mysteriously revert all the changes I made since last succesful (error free save).   I'm able to work around by hitting Ctrl+Z, but obviously this is really annoying.

I'm sure this is related to me doing something wrong, but it seems like it's one thing after another.  I'm a developer so I understand that it can take a while to get the bugs worked out of things, but this is really frustrating.  Is there an alternate way to do this stuff?  Is there anyway I can use Visual Studio?  Is there a more polished version of the Eclipse plugin?  Thanks for any help you guys can give me,

-John