• L0bster1
  • NEWBIE
  • 25 Points
  • Member since 2007

  • Chatter
    Feed
  • 1
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 12
    Replies

I want to update the account object, but the value of the fields involved depends on the results of an IF statement. However, I don't seem to be able to put IF statements in the update record and I couldn't find any good examples to give me a clue.

 

Below is a sample of what I want to do conceptually, but can someone help with the correct syntax?

 

Thank you very much.

 

for(integer i=0; i < trigger.new.size();i++){

ac.add(new Account(
ID = trigger.new[i].AccountID, 

Date_Daily_Demo__c = if(trigger.new[i].Date_Daily_Demo__c > trigger.old[i].Account_Daily_Demo__c){trigger.new[i].Date_Daily_Demo__c}; {trigger.old[i].Account_Daily_Demo__c})

update ac;

 

I can create the related list of tasks that I want, except that the subject field is presented as text instead of as a hyperlink to the task record. Does anyone know why the code below doesn't work? See code in red.

 

 

<apex:page standardController="Contact" extensions="sampleDetailPageCon">
<apex:pageblock id="CustomList" title="Sales Activities"  >
   <apex:pageBlockTable value="{!tsk}" var="o" rendered="{!NOT(ISNULL(tsk))}">
        <apex:column value="{!o.Activitydate}"/>
 
  <apex:outputLink value="https://na8.salesforce.com/{!o.ID}">{!o.subject}</apex:outputLink>
    
        <apex:column value="{!o.This_Task_is_a__c}"/>
        <apex:column value="{!o.Ownerid}"/>
   </apex:pageBlockTable>
 </apex:pageblock>
</apex:page>

 

I want to automatically convert new leads into contacts. I have a trigger on Lead after update that will bulk convert 100 leads at a time. The problem I have  is that my marketing automation tool pushes new leads into Salesforce in batches of 200 at a time. When I try to import 200 leads, the bulk convert fails due to a too many DML 151 error.

 

I read that the convertlead function can only handle 100 records at a time. How can I edit the code to handle 200 imports at a time? Is it possible?

 

Thanks in advance.

 

trigger AutoConvert on Lead (after update) {

for(Lead myLead: Trigger.new){ if(Trigger.new[0].isConverted == false) { Database.LeadConvert lc = new database.LeadConvert(); lc.setLeadId(myLead.Id); lc.convertedStatus = 'Qualified'; //Database.ConvertLead(lc,true); lc.setDoNotCreateOpportunity(true); Database.LeadConvertResult lcr = Database.convertLead(lc); System.assert(lcr.isSuccess()); }}}

 

For background, I'm not a programmer so "Hello World" is cutting edge for me.  My goal is to have a detail page button that when pushed sets the custom field "Followup" to today+7days. The code below used to work for me, but some combination of browser / SF updates has left the code broken and useless.  

 

Can anyone help me either fix the code below or offer an alternative suggestion for accomplishing my goal?

 

Thank you for your time.

 

-Derek 

 

<html>
<head>
<script src="/soap/ajax/8.0/connection.js"
type="text/javascript"></script>
<script>
{
var sfaccount2 = new Date();
sfaccount2.setDate(sfaccount2.getDate()+7)

 

var accounts = sforce.connection.query("Select ID, Followup__c From Lead where Id = '{!Lead.Id}'");
var rec = accounts.getArray("records");

 

for (var i = 0;i<rec.length;i++) {
rec[i].Followup__c = sfaccount2;
}

 

sforce.connection.update(rec);
parent.window.close();
}

 

</script>
</head>
</body>
</html>
 

Here's an S-control I made and presented on at Dreamforce that will populate custom lead fields with the Google Campaign, AdGroup, and AdWord.  The prerequisite for this to work is to have Salesforce for Google Adwords setup and to have the custom lead fields (Google_Campaign__c, AdKeyword__c, Google_AdGroup__c) created.  It also uses a custom lead field called "Last4__c" which is actually a formula field that returns "Yes" if the lead has been created in the last 4 days. I use this to keep the number of leads being updated to a manageable number. I’m posting both to share but also because I bet some of the real talents on this board can improve upon this code.  I’m not a programmer and I owe those on this board a lot of thanks for helping me to learn how to write S-Controls. 

The benefit to this code is that with the SFGA info in custom fields as opposed to tasks you can do all sorts of custom reporting.  I launch this S-Control from a custom homepage component daily in order to populate the custom lead fields before I start the lead conversion process.

Thanks to all on this board who give their time and advice, it is most appreciated.

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

<html>
<head>
<script src="http://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js" type="text/javascript"></script>
<script language="JavaScript">

function initPage()
{
sforceClient.registerInitCallback(updateObjects);
sforceClient.setLoginUrl("https://www.salesforce.com/services/Soap/u/7.0");
sforceClient.init("{!API.Session_ID}", "{!API.Partner_Server_URL_70}", true);
}

function updateObjects()
{
var queryResult3 = sforceClient.query("Select ID, Google_Campaign__c, AdKeyword__c, Google_AdGroup__c From Lead where Last4__c = 'Yes' and LeadSource = 'Google AdWords'")

var updateObjects = new Array();

for (var i=0;i<queryResult3.size;i++)
{
var lhaccount2 = queryResult3.records[i];
var ids=lhaccount2.get("Id");

var queryResultP = sforceClient.query("Select ID, Name From SFGA__Google_Campaign__c where SFGA__Lead__c = '"+ids+"'")
var queryResultK = sforceClient.query("Select ID, Name From SFGA__Keyword__c where SFGA__Lead__c = '"+ids+"'")
var queryResultA = sforceClient.query("Select ID, Name From SFGA__Ad_Group__c where SFGA__Lead__c = '"+ids+"'")

var lhaccount3 = queryResultP.records[0];
var Name=lhaccount3.get("Name");

var lhaccount4 = queryResultK.records[0];
var Keyword=lhaccount4.get("Name");

var lhaccount5 = queryResultA.records[0];
var Group=lhaccount5.get("Name");

lhaccount2.set("Google_Campaign__c", Name);
lhaccount2.set("AdKeyword__c", Keyword);
lhaccount2.set("Google_AdGroup__c", Group);

updateObjects.push(lhaccount2);

}

var saveResults = sforceClient.Update(updateObjects)[0];
parent.window.close();
}
</script>
</head>
<body onload="initPage()">
</body>
</html>


I'm trying to write what I thought was a simple script to first search for some accounts meeting specified criteria and then update some fields on the contact objects that are related to those accounts.  My code is not throwing errors, but also not updating the Contact fields.  I'm hoping one of the experts here can easily spot something I've missed.  Thanks in advance. It may not be much, but most everything I've learned about s-controls has come from this forumn.  My code is below:
 
function updateObjects()
{
//query to get accounts associated with contacts
var queryResult = sforceClient.query("Select ID From Account where OwnerId = '{!$User.Id}' and Account_Status__c = 'Open'")
 
//move results into readable format
var account = queryResult.records[0];
 
// assign attribs to variables
var sfaccount2 = account.get("ID");
var sfaccount = new Date ();
var sfaccount1 = "Active";
 
var queryResult2 = sforceClient.query("Select ID, Automated_Date__c, Automation_Status__c From Contact where AccountId = " + sfaccount2 + "")
 
//new array to hold results of updates
var updateObjects = new Array();
 
// go through list of lhaccounts to update sfaccounts
for (var i=0;i<queryResult2.size;i++)
{
var lhaccount = queryResult2.records[i];
lhaccount.set("Automated_Date__c", sfaccount);
lhaccount.set("Automation_Status__c", sfaccount1);
 
// push updated record into new array for update process
updateObjects.push(lhaccount);
}
 
// submit new array with updated contacts
var saveResults = sforceClient.Update(updateObjects)[0];
parent.window.close();
}

I want to automatically convert new leads into contacts. I have a trigger on Lead after update that will bulk convert 100 leads at a time. The problem I have  is that my marketing automation tool pushes new leads into Salesforce in batches of 200 at a time. When I try to import 200 leads, the bulk convert fails due to a too many DML 151 error.

 

I read that the convertlead function can only handle 100 records at a time. How can I edit the code to handle 200 imports at a time? Is it possible?

 

Thanks in advance.

 

trigger AutoConvert on Lead (after update) {

for(Lead myLead: Trigger.new){ if(Trigger.new[0].isConverted == false) { Database.LeadConvert lc = new database.LeadConvert(); lc.setLeadId(myLead.Id); lc.convertedStatus = 'Qualified'; //Database.ConvertLead(lc,true); lc.setDoNotCreateOpportunity(true); Database.LeadConvertResult lcr = Database.convertLead(lc); System.assert(lcr.isSuccess()); }}}

 

I want to update the account object, but the value of the fields involved depends on the results of an IF statement. However, I don't seem to be able to put IF statements in the update record and I couldn't find any good examples to give me a clue.

 

Below is a sample of what I want to do conceptually, but can someone help with the correct syntax?

 

Thank you very much.

 

for(integer i=0; i < trigger.new.size();i++){

ac.add(new Account(
ID = trigger.new[i].AccountID, 

Date_Daily_Demo__c = if(trigger.new[i].Date_Daily_Demo__c > trigger.old[i].Account_Daily_Demo__c){trigger.new[i].Date_Daily_Demo__c}; {trigger.old[i].Account_Daily_Demo__c})

update ac;

 

I can create the related list of tasks that I want, except that the subject field is presented as text instead of as a hyperlink to the task record. Does anyone know why the code below doesn't work? See code in red.

 

 

<apex:page standardController="Contact" extensions="sampleDetailPageCon">
<apex:pageblock id="CustomList" title="Sales Activities"  >
   <apex:pageBlockTable value="{!tsk}" var="o" rendered="{!NOT(ISNULL(tsk))}">
        <apex:column value="{!o.Activitydate}"/>
 
  <apex:outputLink value="https://na8.salesforce.com/{!o.ID}">{!o.subject}</apex:outputLink>
    
        <apex:column value="{!o.This_Task_is_a__c}"/>
        <apex:column value="{!o.Ownerid}"/>
   </apex:pageBlockTable>
 </apex:pageblock>
</apex:page>

 

Can any one tell me why the code below would return the value

 

8/1/2012 8:00 PM
when the code was executed at

 

8/2/2012 3:38 PM EDT

 

The code was executed in the sandbox by a user in the EDT timezone.

 

LeadsToUpdate.add(new Lead(Id=l.id, Date_Demo__c = Date.today()))

 

I want to automatically convert new leads into contacts. I have a trigger on Lead after update that will bulk convert 100 leads at a time. The problem I have  is that my marketing automation tool pushes new leads into Salesforce in batches of 200 at a time. When I try to import 200 leads, the bulk convert fails due to a too many DML 151 error.

 

I read that the convertlead function can only handle 100 records at a time. How can I edit the code to handle 200 imports at a time? Is it possible?

 

Thanks in advance.

 

trigger AutoConvert on Lead (after update) {

for(Lead myLead: Trigger.new){ if(Trigger.new[0].isConverted == false) { Database.LeadConvert lc = new database.LeadConvert(); lc.setLeadId(myLead.Id); lc.convertedStatus = 'Qualified'; //Database.ConvertLead(lc,true); lc.setDoNotCreateOpportunity(true); Database.LeadConvertResult lcr = Database.convertLead(lc); System.assert(lcr.isSuccess()); }}}

 

For background, I'm not a programmer so "Hello World" is cutting edge for me.  My goal is to have a detail page button that when pushed sets the custom field "Followup" to today+7days. The code below used to work for me, but some combination of browser / SF updates has left the code broken and useless.  

 

Can anyone help me either fix the code below or offer an alternative suggestion for accomplishing my goal?

 

Thank you for your time.

 

-Derek 

 

<html>
<head>
<script src="/soap/ajax/8.0/connection.js"
type="text/javascript"></script>
<script>
{
var sfaccount2 = new Date();
sfaccount2.setDate(sfaccount2.getDate()+7)

 

var accounts = sforce.connection.query("Select ID, Followup__c From Lead where Id = '{!Lead.Id}'");
var rec = accounts.getArray("records");

 

for (var i = 0;i<rec.length;i++) {
rec[i].Followup__c = sfaccount2;
}

 

sforce.connection.update(rec);
parent.window.close();
}

 

</script>
</head>
</body>
</html>
 

I'm trying to write what I thought was a simple script to first search for some accounts meeting specified criteria and then update some fields on the contact objects that are related to those accounts.  My code is not throwing errors, but also not updating the Contact fields.  I'm hoping one of the experts here can easily spot something I've missed.  Thanks in advance. It may not be much, but most everything I've learned about s-controls has come from this forumn.  My code is below:
 
function updateObjects()
{
//query to get accounts associated with contacts
var queryResult = sforceClient.query("Select ID From Account where OwnerId = '{!$User.Id}' and Account_Status__c = 'Open'")
 
//move results into readable format
var account = queryResult.records[0];
 
// assign attribs to variables
var sfaccount2 = account.get("ID");
var sfaccount = new Date ();
var sfaccount1 = "Active";
 
var queryResult2 = sforceClient.query("Select ID, Automated_Date__c, Automation_Status__c From Contact where AccountId = " + sfaccount2 + "")
 
//new array to hold results of updates
var updateObjects = new Array();
 
// go through list of lhaccounts to update sfaccounts
for (var i=0;i<queryResult2.size;i++)
{
var lhaccount = queryResult2.records[i];
lhaccount.set("Automated_Date__c", sfaccount);
lhaccount.set("Automation_Status__c", sfaccount1);
 
// push updated record into new array for update process
updateObjects.push(lhaccount);
}
 
// submit new array with updated contacts
var saveResults = sforceClient.Update(updateObjects)[0];
parent.window.close();
}