• izay.ramos-irizarry1.3893936724146558E12
  • NEWBIE
  • 60 Points
  • Member since 2014

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 13
    Replies
I'm using a custom button to create a new record in a custom object, but the code is failing when I try to insert a value which is type currency during the process.

I have created a custom object called "Project" with an api name of "Production__c".

I have added a custom button to the Opportunity page to create a new Project record and pre-populate it with some fields from the Opportunity.

It works fine until I try to add a value from a currency field, at which point it fails.

If I use no quotes around the value it gives the error "Unexpected number", if I use quotes around it then it give the error "'GBP 1,250' is not valid for the type xsd:double".

So I can't work out how to get the type right, any help would be much appreciated!

Here is the code:

==========

{!REQUIRESCRIPT('/soap/ajax/27.0/connection.js')}

var Proj = new sforce.SObject("Production__c");

Proj.Name = "{!Opportunity.Name}";
//Proj.Monthly_Revenue__c = 1234; **This works**
//Proj.Monthly_Revenue__c = '{!Opportunity.Monthly_Revenue__c}'; **This gives error 'GBP 1,250' not valid for type: xsd:double**
//Proj.Monthly_Revenue__c = {!Opportunity.Monthly_Revenue__c}; **This gives error 'unexpected number'**

result = sforce.connection.create([Proj]);

if(result[0].success == 'true'){
    window.location = "/" + result[0].id + "/e";}
else {alert("Error creating Project");}

============
  • July 31, 2014
  • Like
  • 0
I've got code that works in Developer mode and now need to bring it into production... of course we're supposed to go live tomorrow...
I'm very new to Apex so please excuse the basic question. My code gets called from a visual force page and when I run the test code it can't seem to find the method. I get the error: Method does not exist or incorrect signature

Here is the test code:
@isTest
private class CloneClassAttendanceTest {
//Public CloneClassAttendance(){}
// above line gives error  Invalid constructor name:
    static testMethod void myUnitTest() {
       
        // Add test contact
        Contact c = new Contact(LastName='Test');
        insert c;
        // Add test campaign
        Campaign cp = new Campaign(Name='TestCampaign');
        insert cp;
        // Add campaign member status
        CampaignMemberStatus cms = new CampaignMemberStatus( CampaignId = cp.Id, Label = 'Attended', SortOrder = 3);
        insert cms;
        // Add campaign member
        CampaignMember cm = new CampaignMember( CampaignId = cp.Id, Status = 'Attended', ContactId = c.Id);
        insert cm;
       
        // Call CloneClassAttendance
        InsertRecord();
        // Above line gives error: Method does not exist or incorrect signature
    }
}

Here is that Apex Class:
public class CloneClassAttendance
{
    private final Campaign theCampaign;

    public CloneClassAttendance( ApexPages.StandardController stdController )
    {
        theCampaign = (Campaign)stdController.getRecord();
    }

    //  returns the day-of-week for the given date in 2001 - 2099
    //  this works because 2001 started on a Monday
    //  0 = Sunday, ... 6 = Saturday
    private static Integer dayOfWeek( Date theDate )
    {
        Integer theYear = theDate.year() - 2001;
        return Math.mod( theYear + theYear/4 + theDate.dayOfYear(), 7 );
    }

    public void insertRecord()
    {
        Map<Date,Campaign> map_newCampaigns = new Map<Date,Campaign>();

        Date newDate = theCampaign.CloneStart__c;
        while ( newDate <= theCampaign.CloneEnd__c )
        {
            map_newCampaigns.put
            (   newDate,
                new Campaign
                (   Type                = 'Class Attendance',
                    IsActive            = true,
                    StartDate           = newDate,
                    EndDate             = newDate,
                    ParentId            = theCampaign.Id,
                    Name                = theCampaign.Name + '-' + newDate.format(),
                    Description         = theCampaign.Description,
                    Teacher__c          = theCampaign.Teacher__c,
                    Day_of_Week__c      = theCampaign.Day_of_Week__c,
                    Hours_Per_Class__c  = theCampaign.Hours_Per_Class__c,
                    Location__c         = theCampaign.Location__c,
                    Start_Time__c       = theCampaign.Start_Time__c,
                    End_Time__c         = theCampaign.End_Time__c,
                    Waitlist__c         = theCampaign.Waitlist__c,
                    Max_Capacity__c     = theCampaign.Max_Capacity__c,
                    Status              = 'Completed'
                )
            );
            newDate = newDate.addDays( 7 );
        }
        insert map_newCampaigns.values();

        List<CampaignMemberStatus>  list_newCampaignMemberStatus    = new List<CampaignMemberStatus>();
        List<CampaignMember>        list_newCampaignMembers         = new List<CampaignMember>();

        newDate = theCampaign.CloneStart__c;  
        while ( newDate <= theCampaign.CloneEnd__c )
        {
            Campaign newCampaign = map_newCampaigns.get( newDate );

            for ( CampaignMemberStatus status :
                [   SELECT  Id, HasResponded, IsDefault, Label, SortOrder
                    FROM    CampaignMemberStatus
                    WHERE   (   CampaignId = :theCampaign.Id
                            AND IsDeleted = false
                            )
                ]
                )
            {

                list_newCampaignMemberStatus.add
                (   new CampaignMemberStatus
                    (   CampaignId      = newCampaign.Id,
                        HasResponded    = status.HasResponded,
                        IsDefault       = status.IsDefault,
                        Label           = status.Label,
// the following line is a workaround due to the fact that when the campaign is cloned it automatically
// add CampaignMemberStatus of Sent and Received with sortorder 1 and 2. This was creating a duplicate bug.
                        SortOrder       = status.SortOrder +2
                    )
                );
System.debug( 'CampaignMemberStatus: CampaignId= ' + newCampaign.Id +' Label = ' + status.Label + ', SortOrder = ' + status.SortOrder );
            }

            for ( CampaignMember member :
                [   SELECT  Id, ContactId, Status
                    FROM    CampaignMember
                    WHERE   CampaignId = :theCampaign.Id
                ]
                )
            {
                list_newCampaignMembers.add
                (   new CampaignMember
                    (   CampaignId      = newCampaign.Id,
                        ContactId       = member.ContactId,
                        Status          = member.Status
                    )
                );
            }

            newDate = newDate.addDays( 7 );
        }

        insert list_newCampaignMemberStatus;
        insert list_newCampaignMembers;
    }
}

Here is the VisualForce Page:
<apex:page standardController="Campaign" extensions="CloneClassAttendance" action="{!insertRecord}">

  <h1>Cloning Attendance</h1>
  <p> Class name is {! campaign.name} </p>
  <p> Class id is:   {! campaign.id} </p>
  <p> Class start date is:   {! campaign.startdate} </p>
  <p> Class end date is:   {! campaign.enddate} </p>
  <p> Next week is: {! campaign.startdate+7} </p>
  <p> Class Status is {! campaign.status} </p>
  <p> Class teacher is {! campaign.teacher__c} </p>
  <p> Class DOW is {! campaign.Day_of_Week__c} </p>
  <p> Class Hours_Per_Class__c is {! campaign.Hours_Per_Class__c} </p>
  <p> Class Location is {! campaign.Location__c} </p>
  <p> Class Start time is {! campaign.Start_Time__c} </p>
  <p> Class End time is {! campaign.End_Time__c} </p>
  <p> Class Description is {! campaign.Description} </p>
  <p> Class Waitlist is {! campaign.Waitlist__c} </p>
  <p> Class Max_Capacity is {! campaign.Max_Capacity__c} </p>
  <p> Clone start date is:   {! campaign.clonestart__c} </p>
  <p> Class end date is:   {! campaign.cloneend__c} </p>
</apex:page>
<apex:page showheader="false" sidebar="false">
<apex:iframe src="https://ap1.salesforce.com/01Z90000000MLn7" scrolling="true" height="1588px" width="100%" />
</apex:page>
I'm using a custom button to create a new record in a custom object, but the code is failing when I try to insert a value which is type currency during the process.

I have created a custom object called "Project" with an api name of "Production__c".

I have added a custom button to the Opportunity page to create a new Project record and pre-populate it with some fields from the Opportunity.

It works fine until I try to add a value from a currency field, at which point it fails.

If I use no quotes around the value it gives the error "Unexpected number", if I use quotes around it then it give the error "'GBP 1,250' is not valid for the type xsd:double".

So I can't work out how to get the type right, any help would be much appreciated!

Here is the code:

==========

{!REQUIRESCRIPT('/soap/ajax/27.0/connection.js')}

var Proj = new sforce.SObject("Production__c");

Proj.Name = "{!Opportunity.Name}";
//Proj.Monthly_Revenue__c = 1234; **This works**
//Proj.Monthly_Revenue__c = '{!Opportunity.Monthly_Revenue__c}'; **This gives error 'GBP 1,250' not valid for type: xsd:double**
//Proj.Monthly_Revenue__c = {!Opportunity.Monthly_Revenue__c}; **This gives error 'unexpected number'**

result = sforce.connection.create([Proj]);

if(result[0].success == 'true'){
    window.location = "/" + result[0].id + "/e";}
else {alert("Error creating Project");}

============
  • July 31, 2014
  • Like
  • 0
Hi,

I have a check box field and an apex: inputfield on a visualforce page. The page should initally load with apex:inputfield as readonly (greyout) and as soon as the user ticks the checkbox the field should be available for entering text. How can I achieve this using Javascript?

Thank You.
In my org i have enabled Person Account, and i have a visualforce page where i need to get Salutation,FirstName and LastName field from person account, But when i call it using <apex:inputField value="{!account.lastname}"/> I'm getting only field label here i'm using "account" as a standard controller.

But I have used same line of code i.e <apex:inputField value="{!account.lastname}"/> to get contact's Lastname using "Contact" as standard controller

Here in the below code I'm getting only field label for "Salutation" and "Lastname" but I'm getting both label and field for "Account Name"

can anyone tell me what's problem here ?


<apex:page standardController="Account" extensions="pick_list" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >

   <apex:pageBlockSectionItem >
         <apex:outputlabel value="First Name"/>
         <apex:outputpanel >
         <apex:inputfield value="{!account.Salutation}" />
         &nbsp;
         <apex:inputfield value="{!account.FirstName}" />
         </apex:outputpanel>
  </apex:pageBlockSectionItem>
  <apex:inputfield value="{!account.lastname}"
  <apex:inputfield value="{!account.name}"
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>  
</apex:page>
Hi,

I have a visualforce page with a controller extension. In my save method whenever the user clicks the save button and when the criteria is met the record has to be submitted for approval.

I would really appreciate if someone could please share some sample code for this requirement.

Thanks!
I've got code that works in Developer mode and now need to bring it into production... of course we're supposed to go live tomorrow...
I'm very new to Apex so please excuse the basic question. My code gets called from a visual force page and when I run the test code it can't seem to find the method. I get the error: Method does not exist or incorrect signature

Here is the test code:
@isTest
private class CloneClassAttendanceTest {
//Public CloneClassAttendance(){}
// above line gives error  Invalid constructor name:
    static testMethod void myUnitTest() {
       
        // Add test contact
        Contact c = new Contact(LastName='Test');
        insert c;
        // Add test campaign
        Campaign cp = new Campaign(Name='TestCampaign');
        insert cp;
        // Add campaign member status
        CampaignMemberStatus cms = new CampaignMemberStatus( CampaignId = cp.Id, Label = 'Attended', SortOrder = 3);
        insert cms;
        // Add campaign member
        CampaignMember cm = new CampaignMember( CampaignId = cp.Id, Status = 'Attended', ContactId = c.Id);
        insert cm;
       
        // Call CloneClassAttendance
        InsertRecord();
        // Above line gives error: Method does not exist or incorrect signature
    }
}

Here is that Apex Class:
public class CloneClassAttendance
{
    private final Campaign theCampaign;

    public CloneClassAttendance( ApexPages.StandardController stdController )
    {
        theCampaign = (Campaign)stdController.getRecord();
    }

    //  returns the day-of-week for the given date in 2001 - 2099
    //  this works because 2001 started on a Monday
    //  0 = Sunday, ... 6 = Saturday
    private static Integer dayOfWeek( Date theDate )
    {
        Integer theYear = theDate.year() - 2001;
        return Math.mod( theYear + theYear/4 + theDate.dayOfYear(), 7 );
    }

    public void insertRecord()
    {
        Map<Date,Campaign> map_newCampaigns = new Map<Date,Campaign>();

        Date newDate = theCampaign.CloneStart__c;
        while ( newDate <= theCampaign.CloneEnd__c )
        {
            map_newCampaigns.put
            (   newDate,
                new Campaign
                (   Type                = 'Class Attendance',
                    IsActive            = true,
                    StartDate           = newDate,
                    EndDate             = newDate,
                    ParentId            = theCampaign.Id,
                    Name                = theCampaign.Name + '-' + newDate.format(),
                    Description         = theCampaign.Description,
                    Teacher__c          = theCampaign.Teacher__c,
                    Day_of_Week__c      = theCampaign.Day_of_Week__c,
                    Hours_Per_Class__c  = theCampaign.Hours_Per_Class__c,
                    Location__c         = theCampaign.Location__c,
                    Start_Time__c       = theCampaign.Start_Time__c,
                    End_Time__c         = theCampaign.End_Time__c,
                    Waitlist__c         = theCampaign.Waitlist__c,
                    Max_Capacity__c     = theCampaign.Max_Capacity__c,
                    Status              = 'Completed'
                )
            );
            newDate = newDate.addDays( 7 );
        }
        insert map_newCampaigns.values();

        List<CampaignMemberStatus>  list_newCampaignMemberStatus    = new List<CampaignMemberStatus>();
        List<CampaignMember>        list_newCampaignMembers         = new List<CampaignMember>();

        newDate = theCampaign.CloneStart__c;  
        while ( newDate <= theCampaign.CloneEnd__c )
        {
            Campaign newCampaign = map_newCampaigns.get( newDate );

            for ( CampaignMemberStatus status :
                [   SELECT  Id, HasResponded, IsDefault, Label, SortOrder
                    FROM    CampaignMemberStatus
                    WHERE   (   CampaignId = :theCampaign.Id
                            AND IsDeleted = false
                            )
                ]
                )
            {

                list_newCampaignMemberStatus.add
                (   new CampaignMemberStatus
                    (   CampaignId      = newCampaign.Id,
                        HasResponded    = status.HasResponded,
                        IsDefault       = status.IsDefault,
                        Label           = status.Label,
// the following line is a workaround due to the fact that when the campaign is cloned it automatically
// add CampaignMemberStatus of Sent and Received with sortorder 1 and 2. This was creating a duplicate bug.
                        SortOrder       = status.SortOrder +2
                    )
                );
System.debug( 'CampaignMemberStatus: CampaignId= ' + newCampaign.Id +' Label = ' + status.Label + ', SortOrder = ' + status.SortOrder );
            }

            for ( CampaignMember member :
                [   SELECT  Id, ContactId, Status
                    FROM    CampaignMember
                    WHERE   CampaignId = :theCampaign.Id
                ]
                )
            {
                list_newCampaignMembers.add
                (   new CampaignMember
                    (   CampaignId      = newCampaign.Id,
                        ContactId       = member.ContactId,
                        Status          = member.Status
                    )
                );
            }

            newDate = newDate.addDays( 7 );
        }

        insert list_newCampaignMemberStatus;
        insert list_newCampaignMembers;
    }
}

Here is the VisualForce Page:
<apex:page standardController="Campaign" extensions="CloneClassAttendance" action="{!insertRecord}">

  <h1>Cloning Attendance</h1>
  <p> Class name is {! campaign.name} </p>
  <p> Class id is:   {! campaign.id} </p>
  <p> Class start date is:   {! campaign.startdate} </p>
  <p> Class end date is:   {! campaign.enddate} </p>
  <p> Next week is: {! campaign.startdate+7} </p>
  <p> Class Status is {! campaign.status} </p>
  <p> Class teacher is {! campaign.teacher__c} </p>
  <p> Class DOW is {! campaign.Day_of_Week__c} </p>
  <p> Class Hours_Per_Class__c is {! campaign.Hours_Per_Class__c} </p>
  <p> Class Location is {! campaign.Location__c} </p>
  <p> Class Start time is {! campaign.Start_Time__c} </p>
  <p> Class End time is {! campaign.End_Time__c} </p>
  <p> Class Description is {! campaign.Description} </p>
  <p> Class Waitlist is {! campaign.Waitlist__c} </p>
  <p> Class Max_Capacity is {! campaign.Max_Capacity__c} </p>
  <p> Clone start date is:   {! campaign.clonestart__c} </p>
  <p> Class end date is:   {! campaign.cloneend__c} </p>
</apex:page>
I have a need to be able to recreate the 'Save & Send Update' button functionality on the event screen in APex Code, can anyone help with a code snippet on how to do this please.

Basically I want to have an automated process that monthly creates an 'Event' and then sends out a Meeting invite to all the Invitees.  I particularly want the email functionality that has the 'Respond to This Request' button in the email.

Does anyone know what code is run when the 'Save & Send Update' button is pressed?

Thanks in advance.


  • January 21, 2014
  • Like
  • 0
{"example":{"Os":"windows","Origin":"xyz"}} is my request string that is sent to a HTTPPost REST Web service in salesforce.

@RestResource(urlMapping='/NewIncident/*')
global without sharing class WSIncident {
    @HttpPost
    global static String createMobileCase(string example) {
        contact newCase = new contact();
        JSONParser jParser = JSON.createParser(example);


/*CAN SOME ONE PLEASE HELP ME PARSE THIS JSON*/

     return newCase.Id;
}
}
  • January 17, 2014
  • Like
  • 0
Hi,

I am trying to build a SOQL query and my condition is when Intake date in object 1 is greater than Start date in object 2 and lesser than End date n Object, then I will be getting the id of the record.  Please see my code below:

Object1 obj1 = trigger.new[0];
List<Object2> DateList = [Select id, Start_Date__c, End_Date__c FROM Object2 WHERE obj1.Intake_Date__c > Start_Date__c AND obj1.Intake_Date__c < End_Date__c];

Can someone please suggest a fix to my code?

Thanks!
Here hidden_field__c is a checkbox.

When in the VFP if user changes the checkbox to true in the database it still shows as false and vice-versa

Can someone please point out what's missing in my code.?

This is my simple code

<pre>

public class dataTableCon {

    List<Account> accounts;

    public List<Account> getAccounts() {

        if(accounts == null) accounts = [select name, owner.name,hidden_field__c from account limit 10];

        return accounts;

    }

}

</pre>

<pre>
<apex:page controller="dataTableCon" id="page">
   
    <apex:form >
   
    <apex:pageBlock id="theBlock">
   
    <apex:dataTable value="{!accounts}" var="account" id="theTable" rowClasses="odd,even" styleClass="tableClass">
   
        <apex:column >
            <apex:facet name="header">Private</apex:facet>
            <apex:inputCheckbox value="{!account.hidden_field__c}" >
             <apex:actionSupport event="onchange" rerender="theBlock"/>
           </apex:inputCheckbox>           
        </apex:column>
   
       
        <apex:column >
            <apex:facet name="header">Name</apex:facet>
            <apex:outputText value="{!account.name}"  >
        </apex:column>
   
        <apex:column >
            <apex:facet name="header">Owner</apex:facet>
            <apex:outputText value="{!account.owner.name}"  >
        </apex:column>
       
    </apex:dataTable> 
   
    </apex:pageBlock>
    </apex:form>
</apex:page>  

</pre>
Hi all,

I have the following trigger:

trigger UpdateLocationStatusonLocationUsingMap on Account (before insert) {

for( Account  parent: Trigger.new)
{

List<Location__c > children = [ SELECT Id, Associate__c , Status__c from Location__c  where Associate__c  = :parent.Id];

List<Location__c > childrenToUpdate = new List<Location__c >();


for(Location__c  thischild: children )
{
   if( thischild.Status__c !=  parent.Status__c )
   {
if ( parent.Status__c ==  'Under Deactivation' ||  parent.Status__c ==  'Inactive')
{
       thischild.Status__c =  parent.Status__c ;
      childrenToUpdate.add(thischild);
}
   }
}


   update childrenToUpdate;


}

}

Which works fine and has passed 100 and works in production.
But when it comes running batch using the apex data loader and the .xml, it reaches the governing limit of 100 giving the message:

«Definitely you are using one or more soql query in a loop and hence the number of query executed in one run time is crossing the governing limit of 100 query.......The alternative is to get the values in map beforehand and use map values instead of query in loop.......»

Any suggestions on how to skip the for and introduce a map?

Best Regards,
Stefanos T.