• Ronnie Paton 8
  • NEWBIE
  • 40 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 6
    Replies
HI,

I have started to get the follwoing erro on a custom buttom I have created

arg 0 'sObjects' is an array. But passed in value is not an array

The code that I have is 

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var ProspectObj = new sforce.SObject("Prospect__c"); 
   ProspectObj.ID = '{!Prospect__c.Id}';   
   ProspectObj.Converted__c = 'True';
   dt= new Date();
   dt.setDate(dt.getDate()+0);
   ProspectObj.Converted_Date__c = dt;
var result = sforce.connection.update(ProspectObj);
var status = "{!Prospect__c.Status__c}";
var newRecords = [];
{
   var acct = new sforce.SObject("Account");
   acct.OwnerId = '{!Prospect__c.OwnerId}';
   acct.Name = '{!Prospect__c.Name}';
   acct.Company_Name__c = '{!Prospect__c.Name}';
   acct.Phone = '{!Prospect__c.Phone_1__c }';
   acct.Fax = '{!Prospect__c.Fax__c}';
   acct.Website = '{!Prospect__c.Website__c}';
   acct.ShippingStreet = '{!Prospect__c.Street__c}';
   acct.ShippingCity = '{!Prospect__c.City__c}';
   acct.ShippingState = '{!Prospect__c.State__c }';
   acct.ShippingPostalCode = '{!Prospect__c.Postcode__c}';
   acct.Type = 'Prospect';
   acct.Industry = '{!Prospect__c.Industry__c}';
   acct.Credit_Standing__c = '{!Prospect__c.Credit_Standing__c}';
if("{!Prospect__c.Number_of_Employees__c }" != "") { acct.NumberOfEmployees = "{!TEXT(Prospect__c.Number_of_Employees__c)}"; }
if("{!Prospect__c.Annual_Revenue__c }" != "") { acct.AnnualRevenue = "{!TEXT(Prospect__c.Annual_Revenue__c)}"; }
newRecords.push(acct);
}
var result = sforce.connection.create(newRecords);

if (!result[0].getBoolean("success")) {
    alert(result[0].errors.message);
}

var newRecords = [];
{
   var opp = new sforce.SObject("Opportunity");
   opp.AccountId =  result[0].id;
   opp.OwnerId = '{!Prospect__c.OwnerId}';
   opp.Name = 'TBC';
   opp.Description = '{Prospect__c.Description__c}';
   opp.LeadSource = 'Converted from Prospect';
   opp.StageName = 'Value Proposition';
   opp.Type = 'New Business';
   opp.CampaignId = '{!Prospect__c.CampaignId__c}';
   opp.Opportunity_Type__c = '{!Prospect__c.Lead_Type__c}';
   opp.Prospect_First_Contact_Made__c = 'True';
   opp.Prospect_Opportunity_Identified__c = 'True';
   opp.Prospect_Requirements_Documented__c = 'True';
   opp.Qualified_Need_to_Buy_Confirmed__c = 'True';
   dt= new Date();
   dt.setDate(dt.getDate()+30);
   opp.CloseDate = dt;
newRecords.push(opp);
}
sforce.connection.create(newRecords);

var newRecords = [];
{
   var Con1 = new sforce.SObject("Contact");
   Con1.AccountId =  result[0].id;
   Con1.OwnerId = '{!Prospect__c.OwnerId}';
   Con1.Salutation = '{!Prospect__c.Salutation_1__c}';
   Con1.FirstName = '{!Prospect__c.First_Name_1__c}';
   Con1.LastName = '{!Prospect__c.Last_Name_1__c}';
   Con1.Title = '{!Prospect__c.Title_1__c}';
   Con1.Email = '{!Prospect__c.Email_1__c}';
   Con1.Phone = '{!Prospect__c.Phone_1__c}';
   Con1.MobilePhone = '{!Prospect__c.Mobile_1__c}';
   Con1.DDI__c = '{!Prospect__c.DDI_1__c}';
   newRecords.push(Con1);
}
sforce.connection.create(newRecords);

var newRecords = [];
{
   var Con2 = new sforce.SObject("Contact");
   Con2.AccountId =  result[0].id;
   Con2.OwnerId = '{!Prospect__c.OwnerId}';
   Con2.Salutation = '{!Prospect__c.Salutation_2__c}';
   Con2.FirstName = '{!Prospect__c.First_Name_2__c}';
   Con2.LastName = '{!Prospect__c.Last_Name_2__c}';
   Con2.Title = '{!Prospect__c.Title_2__c}';
   Con2.Email = '{!Prospect__c.Email_2__c}';
   Con2.Phone = '{!Prospect__c.Phone_2__c}';
   Con2.MobilePhone = '{!Prospect__c.Mobile_2__c}';
   Con2.DDI__c = '{!Prospect__c.DDI_2__c}';
   newRecords.push(Con2);
}
sforce.connection.create(newRecords);
var newRecords = [];
{
   var Con3 = new sforce.SObject("Contact");
   Con3.AccountId =  result[0].id;
   Con3.OwnerId = '{!Prospect__c.OwnerId}';
   Con3.Salutation = '{!Prospect__c.Salutation_3__c}';
   Con3.FirstName = '{!Prospect__c.First_Name_3__c}';
   Con3.LastName = '{!Prospect__c.Last_Name_3__c}';
   Con3.Title = '{!Prospect__c.Title_3__c}';
   Con3.Email = '{!Prospect__c.Email_3__c}';
   Con3.Phone = '{!Prospect__c.Phone_3__c}';
   Con3.MobilePhone = '{!Prospect__c.Mobile_3__c}';
   Con3.DDI__c = '{!Prospect__c.DDI_3__c}';
   newRecords.push(Con3);
}
sforce.connection.create(newRecords);
var newRecords = [];
{
   var Con4 = new sforce.SObject("Contact");
   Con4.AccountId =  result[0].id;
   Con4.OwnerId = '{!Prospect__c.OwnerId}';
   Con4.Salutation = '{!Prospect__c.Salutation_4__c}';
   Con4.FirstName = '{!Prospect__c.First_Name_4__c}';
   Con4.LastName = '{!Prospect__c.Last_Name_4__c}';
   Con4.Title = '{!Prospect__c.Title_4__c}';
   Con4.Email = '{!Prospect__c.Email_4__c}';
   Con4.Phone = '{!Prospect__c.Phone_4__c}';
   Con4.MobilePhone = '{!Prospect__c.Mobile_4__c}';
   Con4.DDI__c = '{!Prospect__c.DDI_4__c}';
   newRecords.push(Con4);
}
sforce.connection.create(newRecords);
var newRecords = [];
{
   var Con5 = new sforce.SObject("Contact");
   Con5.AccountId =  result[0].id;
   Con5.OwnerId = '{!Prospect__c.OwnerId}';
   Con5.Salutation = '{!Prospect__c.Salutation_5__c}';
   Con5.FirstName = '{!Prospect__c.First_Name_5__c}';
   Con5.LastName = '{!Prospect__c.Last_Name_5__c}';
   Con5.Title = '{!Prospect__c.Title_5__c}';
   Con5.Email = '{!Prospect__c.Email_5__c}';
   Con5.Phone = '{!Prospect__c.Phone_5__c}';
   Con5.MobilePhone = '{!Prospect__c.Mobile_5__c}';
   Con5.DDI__c = '{!Prospect__c.DDI_5__c}';
   newRecords.push(Con5);
}
sforce.connection.create(newRecords);

if (result[0].success == 'false') {
    alert(result[0].errors.message);
} else {
   window.parent.location = '/006?fcf=00Bb0000003n9OG';
}

This has been working before but has stopped recently and I can't work out why.
 
HI,

I have created a custom object called "Prospects" and am trying to have a custom oneclick button that once clicked creates an account, opportunity & contacts.

I have the following code

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var ProspectObj = new sforce.SObject("Prospect__c"); 
   ProspectObj.ID = '{!Prospect__c.Id}';   
   ProspectObj.Converted__c = 'True';
   dt= new Date();
   dt.setDate(dt.getDate()+0);
   ProspectObj.Converted_Date__c = dt;
var result = sforce.connection.update([ProspectObj]);
var status = "{!Prospect__c.Status__c}";
var newRecords = [];
{
   var acct = new sforce.SObject("Account");
   acct.OwnerId = '{!Prospect__c.OwnerId}';
   acct.Name = '{!Prospect__c.Name}';
   acct.Company_Name__c = '{!Prospect__c.Name}';
   acct.Phone = '{!Prospect__c.Phone_1__c }';
   acct.Website = '{!Prospect__c.Website__c}';
   acct.ShippingStreet = '{!Prospect__c.Street__c}';
   acct.ShippingCity = '{!Prospect__c.City__c}';
   acct.ShippingState = '{!Prospect__c.State__c }';
   acct.ShippingPostalCode = '{!Prospect__c.Postcode__c}';
   acct.Type = 'Prospect';
newRecords.push(acct);
}
var result = sforce.connection.create(newRecords);

var newRecords = [];
{
   var opp = new sforce.SObject("Opportunity");
   opp.AccountId = '{!Account.Id}';
   opp.OwnerId = '{!Prospect__c.OwnerId}';
   opp.Name = '{!Prospect__c.Description__c}';
   opp.LeadSource = 'Converted from Prospect';
   opp.StageName = 'Perception Analysis';
   opp.Type = 'New Business';
   opp.Prospect_First_Contact_Made__c = 'True';
   opp.Prospect_Initial_Meeting_Scheduled__c = 'True';
   opp.Prospect_Opportunity_Identified__c = 'True';
   opp.Prospect_Requirements_Documented__c = 'True';
   opp.Qualified_Need_to_Buy_Confirmed__c = 'True';
   dt= new Date();
   dt.setDate(dt.getDate()+30);
   opp.CloseDate = dt;
newRecords.push(opp);
}
var result = sforce.connection.create(newRecords);

if (result[0].success == 'false') {
    alert(result[0].errors.message);
} else {
   window.parent.location = '/006?fcf=00Bb0000003n9OG';
}

the account is cretaed fine and all fields map over as expected, The opportunity is created but not linked to the account and the account field is blank.

I have tried to create the contacts but they are not created and want to work on 1 thing at a time but the code I addedd is the following

var newRecords = [];
{
   var Con1 = new sforce.SObject("Contact");
   Con1.OwnerId = '{!Prospect__c.OwnerId}';
   Con1.Account = '{!Prospect__c.Name}';
   Con1.FirstName = '{!Prospect__c.First_Name_1__c }';
   Con1.LastName = '{!Prospect__c.Last_Name_1__c}';
   Con1.Title = '{!Prospect__c.Title_1__c}';
   Con1.Email = '{!Prospect__c.Email_1__c}';
   Con1.Phone = '{!Prospect__c.Phone_1__c}';
   Con1.MobilePhone = '{!Prospect__c.Mobile_1__c}';
   Con1.DDI__c = '{!Prospect__c.DDI_1__c}';

newRecords.push(Con1);
}  

I do have 5 sets of above (Con2, Con3, etc) that might no be populated  

I don't get any errors displayed.

Thanks in advance

Ronnie
HI,

I am trying to create a custom button on a custom Object that when clicked creates Account\Contact\Opportunity (like convert button on Lead).

The code I have is 
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var ProspectObj = new sforce.SObject("Prospect__c"); 
   ProspectObj.ID = '{!Prospect__c.Id}';   
   ProspectObj.Converted__c = 'True';
   dt= new Date();
   dt.setDate(dt.getDate()+0);
   Prospect__c.Converted_Date__c = dt;
var result = sforce.connection.update([ProspectObj]);
var status = "{!Prospect__c.Status__c}";
var newRecords = [];
{
   var acct = new sforce.SObject("Account");
   acct.OwnerId = '{!Prospect__c.OwnerId}';
   acct.Name = '{!Prospect__c.Name}';
   acct.ShippingStreet = '{!Prospect__c.Street__c}';
   acct.ShippinggCity = '{!Prospect__c.City__c}';
   acct.ShippingState = '{!Prospect__c.State__c }';
   acct.ShippingPostalCode = '{!Prospect__c.Postcode__c}';
newRecords.push(acct);
}
var result = sforce.connection.create(newRecords);

var newRecords = [];
{
   var opp = new sforce.SObject("Opportunity");
   opp.AccountId = '{!Account.Id}';
   opp.OwnerId = '{!Prospect__c.OwnerId}';
   opp.Name = '{!Prospect__c.Description__c}';
   opp.LeadSource = 'Converted from Prospect';
   opp.StageName = 'Perception Analysis';
   opp.Type = 'New Business';
   opp.Prospect_First_Contact_Made__c = 'True';
   opp.Prospect_Initial_Meeting_Scheduled__c = 'True';
   opp.Prospect_Opportunity_Identified__c = 'True';
   opp.Prospect_Requirements_Documented__c = 'True';
   opp.Qualified_Need_to_Buy_Confirmed__c = 'True';
   dt= new Date();
   dt.setDate(dt.getDate()+30);
   opp.CloseDate = dt;
newRecords.push(opp);
}
var result = sforce.connection.create(newRecords);

if (result[0].success == 'false') {
    alert(result[0].errors.message);
} else {
   window.parent.location = '/a05?fcf=00Bb0000003wFhp';
}

when I click the button I get an error saying that Prospect__c is not defined.

Any pointers would be a great help.

Thanks in Advance

Ronnie

 
Hi All,

I am trying to create a button that converts a case to an opportunity, but have ran into a bit of a brickwall

When I click the button I get the following error

 A problem with the OnClick JavaScript for this button or link was encountered:

{faultcode:,soapenv:Client',faultstring:"03/08/2014' is not a valid value for the type xsd:date',}


The status of the case changes but the opportunity is not created, here is the code I have but not sure if it works totally as can't get past the date issue.

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var caseObj = new sforce.SObject("Case");
   caseObj.Id = '{!Case.Id}';
   caseObj.Status = 'Converted to Opportunity';
var result = sforce.connection.update([caseObj]);
var status = "{!Case.Status}}";
var newRecords = [];
{
   var o = new sforce.SObject("Opportunity");
   o.AccountId = '{!Case.AccountId}';
   o.Type = '{!Case.Type}';
   o.Name = '{!Case.CaseNumber},{!Case.Subject}';
   o.LeadSource = '{!'Converted from Case'}';
   o.Description = '{! Case.Description }';
   o.OwnerId = '{!Account.OwnerId}';
   o.StageName = '{!'Perception Analysis'}';
   o.CloseDate = '{! TODAY() +30}';
newRecords.push(o);
}
var result = sforce.connection.create(newRecords);

if (result[0].success == 'false') {
    alert(result[0].errors.message);
} else {
    parent.ID = '{!Case.ParentId}';
    window.parent.location = ('/00a/e?parent_id=retURL=/{!Case.Id}');}


I know the issue is from the o.CloseDate = '{! TODAY() +30}'; but just can't workout what it should be.

Thanks
 
Hi All,

I am trying to create test code for the Milestone Utilities Class, Trigger on Case Comment, Trigger on Email Message that has been published at

https://developer.salesforce.com/index.php?title=Auto-completion_of_Case_Milestones_with_Triggers&oldid=33636&language=en

The code I have found that I thought would complte this but could be totally wrong is 

@istest

public class CompleteMilestone{
 
  // test methods
  static testMethod void testCompleteMilestoneCase(){
   
    Contact oContact = [select id from Contact limit 1];
    String contactId;
    if (oContact != null)
      contactId = oContact.Id;
   
    Entitlement entl = [select id from Entitlement limit 1];
    String entlId;
    if (entl != null)
      entlId = entl.Id;
   
    List<Case> cases = new List<Case>{};
    if (entlId != null){
      Case c = new Case(Subject = 'Test Case with Entitlement ', EntitlementId = entlId, ContactId = contactId);
      cases.add(c);
    }
   
    // Insert the Account records that cause the trigger to execute.
    if (cases.isEmpty()==false){
      insert cases;
      List<Id> caseIds = new List<Id>();
      for (Case cL : cases){
        caseIds.add(cL.Id);
      }
      milestoneUtils.completeMilestone(caseIds, 'Response MAC', System.now());
        }
    }
 
    static testMethod void testCompleteMilestoneViaCase(){
     
        // Perform data preparation
        Entitlement entl = [select id from Entitlement limit 1];
        String entlId;
        if (entl != null)
            entlId = entl.Id;
        List<Case> cases = new List<Case>{};
        for(Integer i = 0; i < 1; i++){
            Case c = new Case(Subject = 'Test Case ' + i);
            cases.add(c);
            if (entlId != null){
                c = new Case(Subject = 'Test Case with Entitlement ' + i, EntitlementId = entlId);
                cases.add(c);
            }
        }
       
        // Insert the Account records that cause the trigger to execute.
        insert cases;

        List<CaseComment> ccs = new List<CaseComment>{};
        for(Case c : cases){
            CaseComment cc = new CaseComment(CommentBody='TestPublic', IsPublished=true, ParentId=c.Id);
            ccs.add(cc);
            cc = new CaseComment(CommentBody='TestPrivate', IsPublished=true, ParentId=c.Id);
            ccs.add(cc);
        }
        if (ccs.isEmpty()==false)
            insert ccs;
   
    // Now create emailmessage objects for them.
   
        List<EmailMessage> emails = new List<EmailMessage>();
        for(Case c : cases){
            emails.add(new EmailMessage(parentId = c.id));
        }
        if(emails.isEmpty()==false)
            database.insert(emails);
       
        for(Case c : cases){
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            String[] toAddr = new String[] {'mramsey@salesforce.com'};
            mail.setToAddresses(toAddr);
            mail.setSaveAsActivity(false);
            mail.setTargetObjectId(c.ContactId);
            mail.setWhatId(c.Id);
            mail.setHtmlBody('TestHTMLBody');
            mail.setPlainTextBody('TestTextBody');
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        }
   
    for(Case c : cases){
      c.Status = 'Closed';
    }
    update cases;
   
        // Query the database for the newly inserted records.
        List<Case> insertedCases = [SELECT Subject,
                                           Description,
                                          (SELECT IsPublished, CommentBody From CaseComments),
                                          (SELECT TextBody, Subject, Incoming From EmailMessages)
                                           FROM Case
                                           WHERE Id IN :cases];
    }
}

But when I run the test it fails on line 8 colum 1
Contact oContact = [select id from Contact limit 1];

and line 38 column 1
Entitlement entl = [select id from Entitlement limit 1];

both have the following error

System.QueryException; List has no rows for assigment to Sobject

Thanks in advance for any help/pointers you give me

Hi All,

I am trying to create a button that converts a case to an opportunity, but have ran into a bit of a brickwall

When I click the button I get the following error

 A problem with the OnClick JavaScript for this button or link was encountered:

{faultcode:,soapenv:Client',faultstring:"03/08/2014' is not a valid value for the type xsd:date',}


The status of the case changes but the opportunity is not created, here is the code I have but not sure if it works totally as can't get past the date issue.

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var caseObj = new sforce.SObject("Case");
   caseObj.Id = '{!Case.Id}';
   caseObj.Status = 'Converted to Opportunity';
var result = sforce.connection.update([caseObj]);
var status = "{!Case.Status}}";
var newRecords = [];
{
   var o = new sforce.SObject("Opportunity");
   o.AccountId = '{!Case.AccountId}';
   o.Type = '{!Case.Type}';
   o.Name = '{!Case.CaseNumber},{!Case.Subject}';
   o.LeadSource = '{!'Converted from Case'}';
   o.Description = '{! Case.Description }';
   o.OwnerId = '{!Account.OwnerId}';
   o.StageName = '{!'Perception Analysis'}';
   o.CloseDate = '{! TODAY() +30}';
newRecords.push(o);
}
var result = sforce.connection.create(newRecords);

if (result[0].success == 'false') {
    alert(result[0].errors.message);
} else {
    parent.ID = '{!Case.ParentId}';
    window.parent.location = ('/00a/e?parent_id=retURL=/{!Case.Id}');}


I know the issue is from the o.CloseDate = '{! TODAY() +30}'; but just can't workout what it should be.

Thanks
 
HI,

I have created a custom object called "Prospects" and am trying to have a custom oneclick button that once clicked creates an account, opportunity & contacts.

I have the following code

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var ProspectObj = new sforce.SObject("Prospect__c"); 
   ProspectObj.ID = '{!Prospect__c.Id}';   
   ProspectObj.Converted__c = 'True';
   dt= new Date();
   dt.setDate(dt.getDate()+0);
   ProspectObj.Converted_Date__c = dt;
var result = sforce.connection.update([ProspectObj]);
var status = "{!Prospect__c.Status__c}";
var newRecords = [];
{
   var acct = new sforce.SObject("Account");
   acct.OwnerId = '{!Prospect__c.OwnerId}';
   acct.Name = '{!Prospect__c.Name}';
   acct.Company_Name__c = '{!Prospect__c.Name}';
   acct.Phone = '{!Prospect__c.Phone_1__c }';
   acct.Website = '{!Prospect__c.Website__c}';
   acct.ShippingStreet = '{!Prospect__c.Street__c}';
   acct.ShippingCity = '{!Prospect__c.City__c}';
   acct.ShippingState = '{!Prospect__c.State__c }';
   acct.ShippingPostalCode = '{!Prospect__c.Postcode__c}';
   acct.Type = 'Prospect';
newRecords.push(acct);
}
var result = sforce.connection.create(newRecords);

var newRecords = [];
{
   var opp = new sforce.SObject("Opportunity");
   opp.AccountId = '{!Account.Id}';
   opp.OwnerId = '{!Prospect__c.OwnerId}';
   opp.Name = '{!Prospect__c.Description__c}';
   opp.LeadSource = 'Converted from Prospect';
   opp.StageName = 'Perception Analysis';
   opp.Type = 'New Business';
   opp.Prospect_First_Contact_Made__c = 'True';
   opp.Prospect_Initial_Meeting_Scheduled__c = 'True';
   opp.Prospect_Opportunity_Identified__c = 'True';
   opp.Prospect_Requirements_Documented__c = 'True';
   opp.Qualified_Need_to_Buy_Confirmed__c = 'True';
   dt= new Date();
   dt.setDate(dt.getDate()+30);
   opp.CloseDate = dt;
newRecords.push(opp);
}
var result = sforce.connection.create(newRecords);

if (result[0].success == 'false') {
    alert(result[0].errors.message);
} else {
   window.parent.location = '/006?fcf=00Bb0000003n9OG';
}

the account is cretaed fine and all fields map over as expected, The opportunity is created but not linked to the account and the account field is blank.

I have tried to create the contacts but they are not created and want to work on 1 thing at a time but the code I addedd is the following

var newRecords = [];
{
   var Con1 = new sforce.SObject("Contact");
   Con1.OwnerId = '{!Prospect__c.OwnerId}';
   Con1.Account = '{!Prospect__c.Name}';
   Con1.FirstName = '{!Prospect__c.First_Name_1__c }';
   Con1.LastName = '{!Prospect__c.Last_Name_1__c}';
   Con1.Title = '{!Prospect__c.Title_1__c}';
   Con1.Email = '{!Prospect__c.Email_1__c}';
   Con1.Phone = '{!Prospect__c.Phone_1__c}';
   Con1.MobilePhone = '{!Prospect__c.Mobile_1__c}';
   Con1.DDI__c = '{!Prospect__c.DDI_1__c}';

newRecords.push(Con1);
}  

I do have 5 sets of above (Con2, Con3, etc) that might no be populated  

I don't get any errors displayed.

Thanks in advance

Ronnie
HI,

I am trying to create a custom button on a custom Object that when clicked creates Account\Contact\Opportunity (like convert button on Lead).

The code I have is 
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var ProspectObj = new sforce.SObject("Prospect__c"); 
   ProspectObj.ID = '{!Prospect__c.Id}';   
   ProspectObj.Converted__c = 'True';
   dt= new Date();
   dt.setDate(dt.getDate()+0);
   Prospect__c.Converted_Date__c = dt;
var result = sforce.connection.update([ProspectObj]);
var status = "{!Prospect__c.Status__c}";
var newRecords = [];
{
   var acct = new sforce.SObject("Account");
   acct.OwnerId = '{!Prospect__c.OwnerId}';
   acct.Name = '{!Prospect__c.Name}';
   acct.ShippingStreet = '{!Prospect__c.Street__c}';
   acct.ShippinggCity = '{!Prospect__c.City__c}';
   acct.ShippingState = '{!Prospect__c.State__c }';
   acct.ShippingPostalCode = '{!Prospect__c.Postcode__c}';
newRecords.push(acct);
}
var result = sforce.connection.create(newRecords);

var newRecords = [];
{
   var opp = new sforce.SObject("Opportunity");
   opp.AccountId = '{!Account.Id}';
   opp.OwnerId = '{!Prospect__c.OwnerId}';
   opp.Name = '{!Prospect__c.Description__c}';
   opp.LeadSource = 'Converted from Prospect';
   opp.StageName = 'Perception Analysis';
   opp.Type = 'New Business';
   opp.Prospect_First_Contact_Made__c = 'True';
   opp.Prospect_Initial_Meeting_Scheduled__c = 'True';
   opp.Prospect_Opportunity_Identified__c = 'True';
   opp.Prospect_Requirements_Documented__c = 'True';
   opp.Qualified_Need_to_Buy_Confirmed__c = 'True';
   dt= new Date();
   dt.setDate(dt.getDate()+30);
   opp.CloseDate = dt;
newRecords.push(opp);
}
var result = sforce.connection.create(newRecords);

if (result[0].success == 'false') {
    alert(result[0].errors.message);
} else {
   window.parent.location = '/a05?fcf=00Bb0000003wFhp';
}

when I click the button I get an error saying that Prospect__c is not defined.

Any pointers would be a great help.

Thanks in Advance

Ronnie

 
Hi All,

I am trying to create a button that converts a case to an opportunity, but have ran into a bit of a brickwall

When I click the button I get the following error

 A problem with the OnClick JavaScript for this button or link was encountered:

{faultcode:,soapenv:Client',faultstring:"03/08/2014' is not a valid value for the type xsd:date',}


The status of the case changes but the opportunity is not created, here is the code I have but not sure if it works totally as can't get past the date issue.

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var caseObj = new sforce.SObject("Case");
   caseObj.Id = '{!Case.Id}';
   caseObj.Status = 'Converted to Opportunity';
var result = sforce.connection.update([caseObj]);
var status = "{!Case.Status}}";
var newRecords = [];
{
   var o = new sforce.SObject("Opportunity");
   o.AccountId = '{!Case.AccountId}';
   o.Type = '{!Case.Type}';
   o.Name = '{!Case.CaseNumber},{!Case.Subject}';
   o.LeadSource = '{!'Converted from Case'}';
   o.Description = '{! Case.Description }';
   o.OwnerId = '{!Account.OwnerId}';
   o.StageName = '{!'Perception Analysis'}';
   o.CloseDate = '{! TODAY() +30}';
newRecords.push(o);
}
var result = sforce.connection.create(newRecords);

if (result[0].success == 'false') {
    alert(result[0].errors.message);
} else {
    parent.ID = '{!Case.ParentId}';
    window.parent.location = ('/00a/e?parent_id=retURL=/{!Case.Id}');}


I know the issue is from the o.CloseDate = '{! TODAY() +30}'; but just can't workout what it should be.

Thanks
 
Hi All,

I am trying to create test code for the Milestone Utilities Class, Trigger on Case Comment, Trigger on Email Message that has been published at

https://developer.salesforce.com/index.php?title=Auto-completion_of_Case_Milestones_with_Triggers&oldid=33636&language=en

The code I have found that I thought would complte this but could be totally wrong is 

@istest

public class CompleteMilestone{
 
  // test methods
  static testMethod void testCompleteMilestoneCase(){
   
    Contact oContact = [select id from Contact limit 1];
    String contactId;
    if (oContact != null)
      contactId = oContact.Id;
   
    Entitlement entl = [select id from Entitlement limit 1];
    String entlId;
    if (entl != null)
      entlId = entl.Id;
   
    List<Case> cases = new List<Case>{};
    if (entlId != null){
      Case c = new Case(Subject = 'Test Case with Entitlement ', EntitlementId = entlId, ContactId = contactId);
      cases.add(c);
    }
   
    // Insert the Account records that cause the trigger to execute.
    if (cases.isEmpty()==false){
      insert cases;
      List<Id> caseIds = new List<Id>();
      for (Case cL : cases){
        caseIds.add(cL.Id);
      }
      milestoneUtils.completeMilestone(caseIds, 'Response MAC', System.now());
        }
    }
 
    static testMethod void testCompleteMilestoneViaCase(){
     
        // Perform data preparation
        Entitlement entl = [select id from Entitlement limit 1];
        String entlId;
        if (entl != null)
            entlId = entl.Id;
        List<Case> cases = new List<Case>{};
        for(Integer i = 0; i < 1; i++){
            Case c = new Case(Subject = 'Test Case ' + i);
            cases.add(c);
            if (entlId != null){
                c = new Case(Subject = 'Test Case with Entitlement ' + i, EntitlementId = entlId);
                cases.add(c);
            }
        }
       
        // Insert the Account records that cause the trigger to execute.
        insert cases;

        List<CaseComment> ccs = new List<CaseComment>{};
        for(Case c : cases){
            CaseComment cc = new CaseComment(CommentBody='TestPublic', IsPublished=true, ParentId=c.Id);
            ccs.add(cc);
            cc = new CaseComment(CommentBody='TestPrivate', IsPublished=true, ParentId=c.Id);
            ccs.add(cc);
        }
        if (ccs.isEmpty()==false)
            insert ccs;
   
    // Now create emailmessage objects for them.
   
        List<EmailMessage> emails = new List<EmailMessage>();
        for(Case c : cases){
            emails.add(new EmailMessage(parentId = c.id));
        }
        if(emails.isEmpty()==false)
            database.insert(emails);
       
        for(Case c : cases){
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            String[] toAddr = new String[] {'mramsey@salesforce.com'};
            mail.setToAddresses(toAddr);
            mail.setSaveAsActivity(false);
            mail.setTargetObjectId(c.ContactId);
            mail.setWhatId(c.Id);
            mail.setHtmlBody('TestHTMLBody');
            mail.setPlainTextBody('TestTextBody');
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        }
   
    for(Case c : cases){
      c.Status = 'Closed';
    }
    update cases;
   
        // Query the database for the newly inserted records.
        List<Case> insertedCases = [SELECT Subject,
                                           Description,
                                          (SELECT IsPublished, CommentBody From CaseComments),
                                          (SELECT TextBody, Subject, Incoming From EmailMessages)
                                           FROM Case
                                           WHERE Id IN :cases];
    }
}

But when I run the test it fails on line 8 colum 1
Contact oContact = [select id from Contact limit 1];

and line 38 column 1
Entitlement entl = [select id from Entitlement limit 1];

both have the following error

System.QueryException; List has no rows for assigment to Sobject

Thanks in advance for any help/pointers you give me