• Erica Kuhl
  • NEWBIE
  • 25 Points
  • Member since 2005

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 275
    Likes Given
  • 3
    Questions
  • 15
    Replies

Hi All,

 

 I am new in Apex trigger . I am facing problem with bulk data .

I am using a trigger that takes data from one Custom Object and copy in Account object.

It is working fine only for 5 rows I am trying to import more then 5 rows , its shows 

For Insert data in Custom object , I am using Data Loader.

 

System.Exception: Too many SOQL queries 

 

Pls correct the code ...

 

 

trigger accountand_invoice_update on STG_AR_INVOICE__c (after insert) {
 
  List< Account> aList = new List<Account>(); 
  List<STG_AR_INVOICE__c> bList=new List<STG_AR_INVOICE__c>(); 
  STG_AR_INVOICE__c sgtUpd;
 

  Account b;
 
  for (STG_AR_INVOICE__c stg : Trigger.new ){       
         Account[] acc = [select id,name,company_code__c,bu_code__c from account Where Name =:stg.Customer_Name__c and Company_Code__c =:stg.Company_Code__c and Bu_Code__c =:stg.Bu_Code__c];
         if(acc.size()>=1){
         for(integer i=0;i<acc.size();i++){
          b=acc[i] ;
          b.Credit_Limit__c=stg.Credit_Limit__c;
          b.Credit_Available__c=stg.Credit_Available__c;
          b.Net_Credit_Available__c=stg.Net_Credit_Available__c;
          b.OutStanding_Orders__c=stg.OutStanding_Orders__c;
          b.Out_Standing_Net_AR__c=stg.OUT_STANDING_NET_AR__c;
          b.STATUS__c='OLD';        
          aList.add( b );
         
          STG_AR_INVOICE__C [] stgexist=[SELECT ID,NAME,COMPANY_CODE__c,CUSTOMER_NAME__c,CUSTOMER_KEY__C FROM STG_AR_INVOICE__C
                 WHERE BU_CODE__c =:b.BU_CODE__C AND CUSTOMER_NAME__c =:b.NAME AND COMPANY_CODE__c =:b.COMPANY_CODE__c];
         if(stgexist.size()>=1){       
          for(integer j=0;j<stgexist.size();j++){
             sgtUpd=stgexist[j];            
             sgtUpd.Customer_key__c=b.Id;             
             bList.add(sgtUpd); 
          }
         }
         }
         
         }else{
           b = new Account();
           b.Name =stg.CUSTOMER_NAME__c;
           b.COMPANY_CODE__c=stg.COMPANY_CODE__c;
           b.BU_CODE__c=stg.BU_CODE__c;              
           b.Credit_Limit__c=stg.Credit_Limit__c;
           b.Credit_Available__c=stg.Credit_Available__c;
           b.Net_Credit_Available__c=stg.Net_Credit_Available__c;
           b.OutStanding_Orders__c=stg.OutStanding_Orders__c;
           b.Out_Standing_Net_AR__c=stg.OUT_STANDING_NET_AR__c;
           b.STATUS__C='NEW';
          
           aList.add(b);
         }
    }
     upsert aList; 
     update bList;  

 

 

Thanks 

  • March 16, 2009
  • Like
  • 0

On Thursday, December 10th the new Answers community will be livereplacing the current CRM community message boards. At that time the following CRM Community boards willbe moving over to the Developerforce community boards, found here: http://community.salesforce.com/sforce/?category.id=developers

 

  • Mac, Apple, OS X
  • Desktop Integration
  • Formulas and Validation Rules
  • Excel Connector
  • Job Board 

 

The new Answers community will be replacing the current CRMcommunity message boards.  The remaining message boards will be put inread-only mode to preserve historical date and will be accessible via searchfrom the new community.  Answers will be the new home for the CRM Community messageboards giving you an outlet to ask all your burning questionstapping into the knowledge of the Salesforce community and experts.

 

Please leave a comment for any questions or feedback you have about the new Answers community.  Weunderstand this is a big change so we will do all we can to make this as smootha transition as possible.   

 

Thanks for your continued support!

 

On Thursday, December 10th the new Answers community will be livereplacing the current CRM community message boards. At that time the following CRM Community boards willbe moving over to the Developerforce community boards, found here: http://community.salesforce.com/sforce/?category.id=developers

 

  • Mac, Apple, OS X
  • Desktop Integration
  • Formulas and Validation Rules
  • Excel Connector
  • Job Board 

 

The new Answers community will be replacing the current CRMcommunity message boards.  The remaining message boards will be put inread-only mode to preserve historical date and will be accessible via searchfrom the new community.  Answers will be the new home for the CRM Community messageboards giving you an outlet to ask all your burning questionstapping into the knowledge of the Salesforce community and experts.

 

Please leave a comment for any questions or feedback you have about the new Answers community.  Weunderstand this is a big change so we will do all we can to make this as smootha transition as possible.   

 

Thanks for your continued support!

 

We used to have a spot dedicated to jobs in Connect On Demand which was very popular.  Since that has been merged into the Community - I thought it best to re-instate an area for Salesforce Jobs.  It was also in reponse to an idea on the IdeaExchange:  Job Opportunities Board

 

Happy job hunting.

Hello! I'm new to Salesforce Administration and have had success with using APEX Triggers and Classes.

 

Issue: After escalating (changing Status and Owner using assignment rules), I auto-populate a custom field, "Escalated By". This works great. I would like to be able to escalate back to the person who is populated in the "Escalated By" field automatically when changing the status back to Tier-1 (from Engineering status).

 

Question 1: Is there a way using Assignment Rules to do:

 If "Escalated By" <> NULL THEN (Step3) Assign to Escalated_By__c (my custom field).

 

Question 2 (if Question 1 is no): Is APEX the only way to go?

I have a custom button on a list view of contacts that allows users to check off as many as they want and then click the button. The button will check off a custom field on each contact's record.

 

Limited success. This works, but only when I choose 1 or 2 contacts. Any more than that and I get a "sforce is not defined" error.

 

Any insight as to why this is happening?

 

{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")} var connection = sforce.connection; var contactid = {!GETRECORDIDS( $ObjectType.Contact)}; // Make sure at least one Contact is selected if (!contactid.length) { alert("Please select at least one contact to enroll."); } else { var contact_to_update = new Array(); for (var i = 0; i < contactid.length; i++) { var callList = new sforce.SObject("Contact"); // Since we'll be using the update call, we must set the id // on the new job application record. callList.Id = contactid[i]; callList.Spring_Flying_Campaign__c="TRUE"; contact_to_update.push(callList); // Now make the update API call in a try statement so we can // catch any errors. Save the resulting array so we can also // check for problems with individual records. // var callCompleted = false; try { var result = sforce.connection.update(contact_to_update); callCompleted = true; } catch(error) { alert("Failed to update Field with error: " + error); } // Now check for problems with individual records. // if (callCompleted) { for (var i = 0; i < result.length; i++) { if (!result[i].getBoolean("success")) { alert("Contact (id='" + contactid[i] + "') could not be updated with error: " + result[i].errors); } } // Finally, refresh the browser to provide confirmation // to the user that the job applications were rejected. // window.location.reload(true); } } }

 

Note: Modified code from several other users but have forgotten who. So, thanks to those who shared their code!

 

Anybody know of an app that would monitor SFDC API traffic usage?  Ideally I'd get a page or a text message when we reaching a configurable limit.

Thanks,

Amber

We've been working on creating web to lead forms and we've been having much success. However, we now need not only Salesforce to capture the form data, but also another PHP script to mail the leads to other people.

Two Questions
1 - Is there a way to send the variables back to the thanks page from Salesforce so we can continue using them? Either via POST or GET or a cookie.

2 - OR - Is it possible to change the variable names of the custom form fields? The current field name is 00N500000021XlJ and that doesn't work with the JavaScript & cookie scripts we're creating as variables can't start with a number. If we could change that to Newsletter or even SF00N500000021XlJ it would work.

The web to lead forms are a great way to get information into Salesforce, but it then prevents us from continuing to use the form information on our site.

 

Is there any way to get form information back?

Hi,

 

  I am trying to built an lookup functionality using the visualforce. I am able to open a popup window as well as able to display the data on it. whenever I am closing the second page, it is not updating the value to the first page.

 

Here is same  code.value should be displayed in the textbox in the parent form .plz help me .

 

 

Parent Window:

<apex:page controller="popupwindow">
<apex:form >
<apex:inputtext value="{!textval}"/>
<apex:commandLink value="get" onclick="popup('/apex/childwindow')"/><br/>
<script>
function popup(url)
{
newwindow=window.open(url,'name','width=400,height=400,top=0,toolbar=no,personalbar=no,location=no,directories=no,statusbar=no,menubar=no,status=no,re sizable=yes,left=60,screenX=60,top=100,screenY=100');
if (window.focus){newwindow.focus()}
}
</script>

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

 

 

Child Window:

<apex:page controller="popupwindow" sidebar="false">
<apex:form >
<apex:dataTable value="{!accounts}" var="a" cellPadding="4" border="1">
<apex:column headervalue="Account Name">
<apex:commandLink onclick="close1()" action="{!filltextval}">
<apex:param name="name1" value="{!a.Name}"/>
{!a.Name}</apex:commandLink></apex:column>
</apex:dataTable>
<script>
function close1()
{
<!-- parent.window.opener.location.reload(); -->
parent.window.close();
}
</script>
</apex:form>
</apex:page>

 

Controller:

public class popupwindow
{
Public string textval{get;set;}

Public List<Account> getAccounts()
{
List<Account> acclist = [select name from account limit 10];
return acclist;
}

Public void filltextval()
{
textval = apexpages.currentpage().getparameters().get('name1');
}

 

  • March 24, 2009
  • Like
  • 0

Hi All,

 

 I am new in Apex trigger . I am facing problem with bulk data .

I am using a trigger that takes data from one Custom Object and copy in Account object.

It is working fine only for 5 rows I am trying to import more then 5 rows , its shows 

For Insert data in Custom object , I am using Data Loader.

 

System.Exception: Too many SOQL queries 

 

Pls correct the code ...

 

 

trigger accountand_invoice_update on STG_AR_INVOICE__c (after insert) {
 
  List< Account> aList = new List<Account>(); 
  List<STG_AR_INVOICE__c> bList=new List<STG_AR_INVOICE__c>(); 
  STG_AR_INVOICE__c sgtUpd;
 

  Account b;
 
  for (STG_AR_INVOICE__c stg : Trigger.new ){       
         Account[] acc = [select id,name,company_code__c,bu_code__c from account Where Name =:stg.Customer_Name__c and Company_Code__c =:stg.Company_Code__c and Bu_Code__c =:stg.Bu_Code__c];
         if(acc.size()>=1){
         for(integer i=0;i<acc.size();i++){
          b=acc[i] ;
          b.Credit_Limit__c=stg.Credit_Limit__c;
          b.Credit_Available__c=stg.Credit_Available__c;
          b.Net_Credit_Available__c=stg.Net_Credit_Available__c;
          b.OutStanding_Orders__c=stg.OutStanding_Orders__c;
          b.Out_Standing_Net_AR__c=stg.OUT_STANDING_NET_AR__c;
          b.STATUS__c='OLD';        
          aList.add( b );
         
          STG_AR_INVOICE__C [] stgexist=[SELECT ID,NAME,COMPANY_CODE__c,CUSTOMER_NAME__c,CUSTOMER_KEY__C FROM STG_AR_INVOICE__C
                 WHERE BU_CODE__c =:b.BU_CODE__C AND CUSTOMER_NAME__c =:b.NAME AND COMPANY_CODE__c =:b.COMPANY_CODE__c];
         if(stgexist.size()>=1){       
          for(integer j=0;j<stgexist.size();j++){
             sgtUpd=stgexist[j];            
             sgtUpd.Customer_key__c=b.Id;             
             bList.add(sgtUpd); 
          }
         }
         }
         
         }else{
           b = new Account();
           b.Name =stg.CUSTOMER_NAME__c;
           b.COMPANY_CODE__c=stg.COMPANY_CODE__c;
           b.BU_CODE__c=stg.BU_CODE__c;              
           b.Credit_Limit__c=stg.Credit_Limit__c;
           b.Credit_Available__c=stg.Credit_Available__c;
           b.Net_Credit_Available__c=stg.Net_Credit_Available__c;
           b.OutStanding_Orders__c=stg.OutStanding_Orders__c;
           b.Out_Standing_Net_AR__c=stg.OUT_STANDING_NET_AR__c;
           b.STATUS__C='NEW';
          
           aList.add(b);
         }
    }
     upsert aList; 
     update bList;  

 

 

Thanks 

  • March 16, 2009
  • Like
  • 0

I am usinf after insert Trigger.

 

 

trigger import_into_stg on STG_AR_INVOICE__c (after insert) {

// Create new Customer
List <Account> toBeInserted = new List<Account>();

// Instantiate a list of Accounts to update
List< Account> aList = new List<Account>();
List<Account> allAcc= new List<Account>();

util t=new util();

// Instantiate a list of STG_AR_INVOICE to populate Customer Key
List< STG_AR_INVOICE__C > stgList = new List< STG_AR_INVOICE__C >();
List< STG_AR_INVOICE__C > updatestg = new List< STG_AR_INVOICE__C >();

Boolean updateFlage;

for ( STG_AR_INVOICE__c stg : Trigger.new ){

Account[] a=[SELECT NAME,COMPANY_CODE__c,BU_CODE__C,SOURCE_CUSTOMER_ID__c FROM ACCOUNT
WHERE BU_CODE__c =:stg.BU_CODE__C AND NAME =:stg.CUSTOMER_NAME__c AND COMPANY_CODE__c =:stg.COMPANY_CODE__c];

Account b;
IF(a.size()>=1){
for(integer i=0;i<a.size();i++){
b=a[i];
}
b.NAME =stg.CUSTOMER_NAME__c;
b.Credit_Limit__c=stg.Credit_Limit__c;
b.Credit_Available__c=stg.Credit_Available__c;
b.Net_Credit_Available__c=stg.Net_Credit_Available__c;
b.OutStanding_Orders__c=stg.OutStanding_Orders__c;
b.Out_Standing_Net_AR__c=stg.OUT_STANDING_NET_AR__c;
aList.add( b );

// Update the Account
if(aList.size()>=1){
update aList;
updateFlage = TRUE;
}

//Back in Staging table and populate record key
if(updateFlage){
STG_AR_INVOICE__C [] stgexist=[SELECT ID,NAME,COMPANY_CODE__c,BU_CODE__C,SOURCE_CUSTOMER_ID__c,CUSTOMER_KEY__C FROM STG_AR_INVOICE__C
WHERE BU_CODE__c =:stg.BU_CODE__C AND SOURCE_CUSTOMER_ID__c =:stg.SOURCE_CUSTOMER_ID__c AND COMPANY_CODE__c =:stg.COMPANY_CODE__c];
STG_AR_INVOICE__C stgupdate;
if(stgexist.size()>0){
for(integer i=0;i<stgexist.size();i++){
stgupdate=stgexist[i];
}
stgupdate.CUSTOMER_KEY__C=b.Id;
stgList.add(stgupdate);


}
}
}else{
updateFlage = false;
// loop through trigger records
//System.debug('In Trigger Create Customer');

Account CreateAccnt = new Account();
CreateAccnt.Name =stg.CUSTOMER_NAME__c;
CreateAccnt.COMPANY_CODE__c=stg.COMPANY_CODE__c;
CreateAccnt.BU_CODE__c=stg.BU_CODE__c;

CreateAccnt.Credit_Limit__c=stg.Credit_Limit__c;
CreateAccnt.Credit_Available__c=stg.Credit_Available__c;
CreateAccnt.Net_Credit_Available__c=stg.Net_Credit_Available__c;
CreateAccnt.OutStanding_Orders__c=stg.OutStanding_Orders__c;
CreateAccnt.Out_Standing_Net_AR__c=stg.OUT_STANDING_NET_AR__c;

toBeInserted.add(CreateAccnt);



// Update Staging table

String accId=t.getAccountId(stg.BU_CODE__C,stg.Company_Code__c,stg.Customer_Name__c);

if(accId !=null){
STG_AR_INVOICE__C [] updstg=[SELECT ID,NAME,COMPANY_CODE__c,BU_CODE__C,SOURCE_CUSTOMER_ID__c,CUSTOMER_KEY__C FROM STG_AR_INVOICE__C
WHERE BU_CODE__c =:stg.BU_CODE__C AND SOURCE_CUSTOMER_ID__c =:stg.SOURCE_CUSTOMER_ID__c AND COMPANY_CODE__c =:stg.COMPANY_CODE__c];
STG_AR_INVOICE__C stgupdate;
if(updstg.size()>0){
for(integer i=0;i<updstg.size();i++){
stgupdate=updstg[i];
}
stgupdate.CUSTOMER_KEY__C=b.Id;
updatestg.add(stgupdate);

}
}
}


}

if(stgList.size()>0){
update stgList;
}
if(toBeInserted.size()>0){
insert toBeInserted;
updateFlage =true;
}

if(updatestg.size()>0 && updateFlage){
update updatestg;
}
updateFlage =false;
}

 

 

Apex Class 

 

 

public class util{

public List<Account> copyCustomersFromERP(String bu_code,String company_code,String customer_name,Double credit_limit){

// Check First Customer exist or not.
//private isCustomerExist=false;
List <Account> toBeInserted = new list<Account>();
/*
String bu_code='100';
String company_code='FMA';
String source_customer_id='DELL';
*/
/*
Integer count=[SELECT Count() FROM Account act
Where act.BU_CODE__c=: bu_code AND act.COMPANY_CODE__c=:company_code AND act.NAME =:customer_name];
*/


//IF(count <= 0){
// loop through trigger records
//for (Integer i=0; i<Trigger.new.size(); i++){
Account CreateAccnt = new Account();
CreateAccnt.Name = customer_name;
CreateAccnt.COMPANY_CODE__c= company_code;
CreateAccnt.BU_CODE__c = bu_code;
CreateAccnt.Credit_Limit__c=credit_limit;
toBeInserted.add(CreateAccnt);
// }

//}
return toBeInserted;
}


}

 

 

 

 

 I am new in Apex trigger . 

 

When I am Inserting bulk data then it is showing Exception

System.Exception: Too many SOQL queries: 21 

Please any Body Suggest me how can I do. Please correct my code.

 

Please also describe me how "after trigger" works. I have confusion that whether it work row by row or after complete all insertion.

 

 

 

 

Thanks in Advance !!!

 

 

 

 

  • March 14, 2009
  • Like
  • 0

Is Connect for Outlook available in the Developer Edition?

If not, why not?

 

How can someone with a Developer Edition become experienced with the product in order to advise a client?

  • February 12, 2009
  • Like
  • 0

I would like to be able to either add an aditinal email address when someone submits a web-to-lead form or just change the one being used by default from the form.

 

Is there a way to do this??

  • January 29, 2009
  • Like
  • 0
Here's what i need to figure out
 
i already created my formula text field that say's
 
IF(date_field__c >= TODAY(), "Entitled", "Not Entitled")
 
But i need to add something that would take into account
 
and If past value = entitled and ''query=xyz'' then .....
 
how can i have a past value into an ''IF''  formula
 
thanks
  • December 10, 2008
  • Like
  • 0
Hello All,
 
When I close a case I want the Case Status field to update to Closed automatically. Any chance anyone can send me the code to create a New Close Case button that will do that or adjust the current one?
 
Renee
Is there anyway to mass e-mail a specific "account" view?  I know you can do it with campaigns, but the people I need to contact are all contained within the "accounts" field.
  • December 02, 2008
  • Like
  • 0
Hi all,

I am using Eclipse as a deployment tool for the first time. Among the changes I wanted to migrate from my Sandbox environment to the Production one, I had an email template that is used in workflow rules for the Opp Line Item standard object.

So I tried to migrate the workflows for this object. The problem is that, on the Sandbox environment, all the email addresses for the users have been suffixed with the name of the Sandbox (eg: an email which in Production is "joe.blogs@somewhere.com" will have the email changed in a Sandbox called test to: "joe.blogs@somewhere.com.test") and Eclipse throws an error (a good thing, for sure!).

The question is: how are you supposed to perform the migration without having to update all the email addresses? What is the ideal way to do this? Thanks,

J
  • November 29, 2008
  • Like
  • 1

Dear All,

 

We want to limit the user permission in Salesforce plugin, and changed the O_Dictonary.xml file to this:

 

<OverrideOptions value="true">

<PutRegistry name="DisplaySplash" type="string" value"false"/> <PutRegistry name="DoNotRevertOptions" type="string"

value"true"/>

<PutRegistry name="ModifyConflictResolution" type="string"

value"false"/>

<PutRegistry name="ModifyFieldMappings" type="string"

value"true"/>

<CanModifySyncEntities value="true" />

<Sync entity="Contact" value="false" />

<Sync entity="Event" value="true" />

<Sync entity="Task" value="true" />

<CanModifySyncDirection value="false" /> <SyncDirection entity="Contact" value="Both" /> <SyncDirection entity="Event" value="Import" /> <SyncDirection entity="Task" value="Export" /> <CanModifyConflictResolution value="false" /> </OverrideOptions> </Document>

 

But when I try to start up outlook afterwards, outlook crashes, and afterwards the salesforce plug-in is missing.

 

Can anybody help to tell me how the Put Registry strings needs to look like?

 

Thank you very much.

 

Best Regards
Ryan He

  • November 28, 2008
  • Like
  • 1
Hi,  I would like to access a field in my trigger.  The field is called Type.  It is a picklist located within the StageName Picklist in the Opportunity object.  (Not to be confused with the Opportunity - Type field)
 
.........
 for (Opportunity a: Trigger.New) {
  if (a.StageName(would like to access Type here) == 'Closed Won') {

...........
 
How can I access it?  Thank you.
  • November 25, 2008
  • Like
  • 1
Hi,
 
I have some classes deployed to my production-system and now I want to delete some of them. When I right-klick on the delete button in my Eclipse project I get a message wich I have to confirm - until there everythin works fine.
 
But after I had confirmed this delete-message I get an Error-Message:
 
"Remote delete failed with the following message. Delete will be aborted. SOmyInitConCalcTrigger_isTest: null package.xml: null"
 
So, can anyone help me out or is there another way do delete the class in the production-system, because in sf I can't find any way to delete this classes?!
 
Thanks in advance for any help
regards
Sascha
Has anyone experienced an issue installing Entitlements 2.09?
 
 
I get a "Request in Progress. You will be notified by email when it completes" message, but that was 4 days ago and it is still not installed.
Any help would be appreciated.
 
Thanks.
 
SControl: AttendeeCount
Desc: Attendee count for hidden field on a custom object (Conference) that is related to Contacts

This one is a bit tricky but useful if you do not have a master child relationship between your two objects. The trick is to add a hidden SControl on the parent object that is going to execute each time the page is viewed. It should query the related child data and if your query data does not match update your summary field and refresh the page. Warning: Don't get caught in a loop.


Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<script src="/soap/ajax/10.0/connection.js"></script>
<script src="/js/dojo/0.4.1/dojo.js"></script>

<script>
dojo.addOnLoad(init);

function init() { 
  countResult = sforce.connection.query("SELECT id FROM Contact WHERE Conference__c = '{!Conference__c.Id}'");
  //alert(countResult.size);
  //alert({!Conference__c.AttendeeCountHidden__c});
  if (countResult.size != {!Conference__c.AttendeeCountHidden__c}) {
    conf = sforce.connection.retrieve("AttendeeCountHidden__c", "Conference__c", ["{!Conference__c.Id}"]);
    conf[0].AttendeeCountHidden__c = countResult.size;
    conf = sforce.connection.update(conf);
    if (conf[0].getBoolean("success")) {
      window.top.location.href = "/{!Conference__c.Id}"
    } 
  }
}
</script>

 





  • December 09, 2007
  • Like
  • 1
I am developing a Ajax scontrol(Report) where I show next 100/50/25 days Events.Customer is asking for pagination as there are thousands of events.
Could some body please provide guidelines or samples for the best practices to use.
Thanks,
Sean
 
  Hi,

I try to use the Xcel connector to access fields in the Account tabs.
One of my custom field is not listed in step 2 of the wizard, so I can access it.
Data type for this field is Lookup(user). Is there any way I can access it ?

Thanks
I am using Flex toolkit version R3.1 and am never seeing anything in the describeSObjectResult.fields property for either a native or custom object. Other properties show up fine but the fields property, while not null, always has a length of 0.
 
Also, the ObjectUtil.toString() utility function shows the fields.
 
Code:
private function describeSObjectsSample():void {
  
  apex.describeSObjects(["Contact", "KAILEA__change__c"], 
      new AsyncResponder(describeSObjects2, genericFault));
}
    
private function describeSObjects2(describeSObjectResults:Array):void {
  for (var i:int=0; i<describeSObjectResults.length; i++) {
    describeSObject2(describeSObjectResults[i]);
  }
}    
          
private function describeSObject2(describeSObjectResult:DescribeSObjectResult):void {
  var objectName:String = describeSObjectResult.name;

  Alert.show("Object name: " + objectName
    + ", createable: " + describeSObjectResult.createable
    + ", queryable: " + describeSObjectResult.queryable
    + ", updateable: " + describeSObjectResult.updateable
    + ", custom: " + describeSObjectResult.custom
    );

  Alert.show("toString(): " + ObjectUtil.toString(describeSObjectResult));

    var fields:Array = describeSObjectResult.fields;
    Alert.show("describeSObject2() have fields? " + (fields != null));
    Alert.show("describeSObject2() fields.length: " + fields.length);
    for (var f:int=0; f<fields.length; f++) {
      var field:Field = fields[f];
      Alert.show("field: " + field.name);
    } // next field
}

 
Thanks in advance for any help!
 
-Roger
These boards have numerous threads about sending emails from s-controls.  Having just wrestled with a variant of the problem for a customer, I thought I'd post the solution I used, which (now!) seems fairly straightforward (although it took some bobbing & weaving to get here).

Problem Statement
:  With one click, allow a user to create an object, then send a template-based email to a Contact associated with that object.  The email template must populate with correct values from the just-created object.

Solution:  Save the following code as an s-control snippet.  Then include the snippet, and call the function from anywhere in your main s-control.  (I won't cover the part about creating a new object here - let's assume you can do that, and then retrieve the object ID of your newly created object.)

function sendEmail(templateId, contactIdForToAddress, relatedObjectId) {

  var url = "https://na3.salesforce.com/email/author/emailauthor.jsp?";
  url += "p2_lkid=" + contactIdForToAddress;
  url += "&p3_lkid=" + relatedObjectId;
  url += "&template_id=" + templateId;
  url += "&new_template=1";
  url += "&retURL=%2F" + relatedObjectId;
  url += "&nosave=0";   // not sure what this parameter does, or if it's really needed
  url += "&save=1";   // send it now - don't just bring us to the "send email" page

  window.open(url);
}


The net effect here is that a new window (actually, a tab in Firefox) will open up, pointing at the newly created object.  If it has an Activity History related list, the just-sent email will appear there. 

This all worked rather elegantly for me.  The actual use case is a Google Map showing the location of various Communities (a custom object).  The user can select several Communities (from a sidebar with a list of accounts & checkboxes), then click a single button to create "Referrals" (a custom object) to each selected Community, and email each Community's primary contact with their Referral data.  After the click, the user waits a moment, and then multiple tabs open up, one for each newly-created Referral.

I'm happy to discuss further if anyone is interested or needs help doing something similar - glenn@appirio.com.


Message Edited by GlennAtAppirio on 02-18-2007 01:05 PM

Message Edited by GlennAtAppirio on 02-18-2007 01:05 PM

Hi--

Can someone explain to me why, when I use the IN join, I am getting an "Unexpected Token: Id" error?

It doesn't always happen, which makes it difficult to tell why it does.  Just now, I ran a query to pull a set of Contacts with the Account ID in column E.  Next, I wanted to pull some Account information for Accounts in the previous query.  A perfect time for "IN," right? 

But when I structured the query to find "Account ID IN E:E," I get an error message that says in full:

Salesforce: Query()
invalid Range, missing data type, or other error,
type is: Account

select id from Account where ID in 'E:E'
                             ^
Error at Row:1:Column:31
Unexpected token: Id


(And to make things more confusing for me, there is nothing in Column 31.)

Help?

Thanks,
Dan
  • October 24, 2006
  • Like
  • 1
I had reinstalled sforce and found the problem that it was looking at the old spot where sforce connector was located. It irked me that the fix for the problem was inadequate. Here's the steps that worked for me.

1. Open up excel
2. RIGHT click the area where the sforce connector button would usually lie.
    A dropdown menu should appear with the last option being "Customize"
3. Click on "Customize"
4. The Customize window should appear. Scroll down to the bottom until you see sforce Connector.
5. LEFT click to highlight the sforce Connector, and click delete.
6. When it asks if you are sure you want to delete it, click Yes.
7. Click Close
8. You are back to where you started. Click Tools
9. Click Add-Ins
10.  Click browse and select the sforce_connect_for_.xla
11. It will say the file already appears, do you want to replace? Click yes.

Finally!
If you don't see the sforce connector button, Right click the area where the sforce connect button would usually lie, and make sure there's a checkmark next to the sforce Connector in the drop down menu (where you saw Customize before)

That should work.
Hi, wondering if it's possible to create an s-control that:

* initiates creation of a record (let's say an Opportunity)
* sets the needed foreign keys
* sets the Record Type
* fills in certain fields in the form (amount and date, for example)
* leaves the user in Edit mode with option to complete/commit or cancel

If so, does anyone have an example they could point me to?

I've seen the technique where the record is created & committed via code, then pulled up in edit mode.  But I'd prefer to give control back to the user before the rec is committed.

Sorry if this is old hat - a quick search of the forum didn't turn up the answer.

Thanks!
Matthew
  • April 12, 2006
  • Like
  • 1
I've promised to post a how-to kind of document after the Winter '06 release, but my time is rather short at the moment. I'll get to it eventually with some example, in production code, but it won't be for a bit yet... Given the number of posts here and elsewhere asking how to do this I thought I'd give some of you a head start. But first a small disclaimer:


WARNING: READ THIS FIRST

THIS TECHNIQUE IS NOT SUPPORTED BY SALESFORCE.COM -- IF YOU HAVE ANY PROBLEMS, DON'T EVEN BOTHER CALLING
READ THIS ENTIRE POST BEFORE ATTEMPTING THESE CHANGES. If you make a mistake you may render your page layout unuseable and uneditable. Possibly even undeleteable.

USE AT YOUR OWN RISK


You can modify actions in the UI on the following pages:
Any Standard or Custom Object Display, Edit, or Print Preview Page, and the user's Home Page

You cannot modify the UI using this method on report pages, the setup pages, and probably several other locations I can't think of at the moment.


What you will need to do is to write some JavaScript code that will execute on the client-side that will locate using the browser DOM the elements you want to edit. For example I change the destination of a "New" button on one of my related list entries. Because there are multiple "New" buttons on the page you will need to check the SFDC-provided destination of the link. It so happens that the related list is a custom object who's id's start with "a00", so I check the link for the string "/a00" and then alter accordingly.

Once you have your JS code you need to get it to execute on the browser.

First create a new Custom S-Control in setup. Give it an appropriate name, and paste your JS code you've written into the "HTML Body" section. Don't include any HTML in the JS, but do include the HTML/JS comment delimiter open/closings on your code. Save your control and view it. You should have a URL that starts with https://na1.salesforce.com/01N... Take note of the object ID (the 01N...
part) and continue on...

If this code will execute on the home page you'll need to have the "Messages and Alerts" home page component enabled. Edit it, and create a HTML script tag with the src url:

/servlet/servlet.Integration?lid=01N...&enc=UTF-8

Replace 01N... with the object ID you saved above.

That's pretty easy, and really doesn't push the limits too far, but how do we get the code to execute on the individual object pages? Ah ha...

WARNING: Again, this is not supported by SFDC, and if done improperly could break your page layout(s). SFDC may decide this is a bug and patch the system, breaking this method. Proceed at your own risk.

In the Page Layout you can give section headers custom names (with some exceptions). These section names are allowed to be very long, and allow you to use unfiltered HTML. One word of caution, when you make these changes below, use a copy of your page layout. If you make a typo, like forgetting a less then or greater then symbol you will break the HTML on the page and very likely break the ability to delete the section or edit it further. You have been warned!

1. After cloning your page layout, edit it and edit a section name. 2. If your section name before was "Section" insert an HTML script tag in front or behind the section name in the same format as the one above in the HTML message box. 3. Save your layout.

Some cautionary words - again, do this at your own risk, but the abilities this leaves us are seemingly unlimited. Do note that straight JS code will execute as the page is loading, not after it completes. You'll need to hook an on-load event to the page to delay execution until after the load is complete.

I'm sorry I couldn't post the actual script tags and whatnot but the forum tends to actually render those as HTML, not as text.
  • January 12, 2006
  • Like
  • 1
fresh doc, pushed yesterday on the appexchange resource page, new publisher info.

http://www.salesforce.com/appexchange/resources_appexchange.jsp

Download the step-by-step guide to publishing apps on the AppExchange
http://www.salesforce.com/us/appexchange/resources/salesforce_appexchange_publish_guide.pdf

Also, please let us know what other doc you feel is missing to help tie together the entire AppExchange vision with complete documentation on how to develop and publish for the platform. We are working on more docs, so I want to make sure these cover the areas that are of concern to this community.

thanks,

not that you would ever need this, however it appears that the AJAX sforceClient does not like 15 charID's in Retrieve, so I ported this late last night from the java version posted elsewhere.

only tested for a short time, but it appears to work.

function normaliseSforceID( id) { // fluff up a 15 char id to return an 18 char id
 if (id == null) return id;
 id = id.replace(/\"/g, ''); // scrub quotes from this id
 if (id.length != 15) {
  //print('well, id is not 15, bye' + id + ' ' + id.length);
  return null;
 }
 var suffix = "";
 for (var i = 0; i < 3; i++) {
  var flags = 0;
  for (var j = 0; j < 5; j++) {
   var c = id.charAt(i * 5 + j);
   if (c >= 'A' && c <= 'Z') {
    flags += 1 << j;
   }
  }
  if (flags <= 25) {
   suffix += "ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(flags);
  } else {
   suffix += "012345".charAt(flags-26);
  }
 }
 return id + suffix;
}

 

I'm loving the new AJAX toolkit! However, I am running into an issue with the following code excerpt. I am looping through currentReps (which is queryResult.records array). For each record, I create a new DynaBean and set some data. The call to getUserQuota does another sforceClient.Query(...) and returns the first record returned.

When getUserQuota() returns, it looks like my estimateSplit (which should be of type Estimate_Split__C) DynaBean has been magically transformed into type User_Quota__c.

Is there a limitation on writing re-entrant code with the library? If so, is there a way to get around this?

Thanks

Todd Breiholz
Meredith Corporation


function convertToEstimateSplits(currentReps) {
var estimateSplits = new Array(currentReps.length);
var i;
for (i = 0; i < currentReps.length; i++) {
var estimateSplit = new DynaBean("Estimate_Split__c");
var advSplit = currentReps[i];
alert("stop");
estimateSplit.set("estimate_net_net_revenue__c", opportunityNetNetRevenue);
estimateSplit.set("ownerid", advSplit.salesrep__c);
estimateSplit.set("pub_issue__c", campaignId);
estimateSplit.set("estimate_split__c", advSplit.advsrep_accnt_prcnt__c);
var quota = getUserQuota(estimateSplit.ownerid);
if (quota != null) {
estimateSplit.set("split_rep_fiscal_quota__c", quota.quota_amount__c);
estimateSplit.set("estimate_quota_fy__c", quota.quota_fy__c);
}
estimateSplits[i] = estimateSplit;
}
return estimateSplits;
}
function getUserQuota(userId) {
var fiscal = accountingPeriodToFiscal();
var userQuotaResult = sforceClient.Query("select Quota_Amount__c, Quota_FY__c from User_Quota__c where Quota_FY__c = '" +
fiscal +
"' and User__c = '" +
userId +
"'");
return userQuotaResult.records[0];
}
  • August 18, 2005
  • Like
  • 1

If you ever had any question regarding how to build S-Controls check out this blog post

http://blog.sforce.com/sforce/2005/07/ajax_toolkit.html

Message Edited by DevAngel on 07-30-2005 09:42 AM

We've found a problem in the userID  returned from the SOAP (2.0) login call. The returned userID is truncated to 15 characters, whereas the same userID returned from a user query is 18 characters. This is causing problems with our ability to correlate these Ids.

I've prefer not to bake work around logic if there is a better solution (like an API fix).

Thanks,

-- Mark

Hi,

I have a developer edition and need to understand how to gain access to this new feature. Does this have to be enabled for the developer edition too? Also if you can point me to some tutorials or documents about this it will be great.

Thanks