• jmaskell123
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 15
    Replies

Hi All,

 

Can anyone see the error in my code for creating renewal opportunies.

 

 

try{ {!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")} // ** EDIT THIS QUERY TO LIST THE FIELDS YOU WANT TO COPY ** var result = sforce.connection.query("Select o.Type, o.StageName, o.Description, o.CloseDate, o.Amount, o.AccountId From Opportunity o WHERE o.Id = '{!Opportunity.Id}'"); var newOpp = result.getArray("records"); // Reset the Opp Id and reset fields to default values newOpp[0].Id = ''; newOpp[0].Name = "Renewal - {!Opportunity.Name}"; // ** EDIT THESE FIELDS TO SET DEFAULT ANY VALUES ** newOpp[0].StageName = "Prospecting"; newOpp[0].Type = "Renewal" newOpp[0].CloseDate = {!Opportunity.CloseDate + 365}; var saveResult = sforce.connection.create(newOpp); if (saveResult[0].getBoolean("success")) { newOpp[0].id = saveResult[0].id; alert("Renewal Opportunity Has Been Created."); } else { alert("Failed to create clone: " + saveResult[0]); } // Refresh the page to display the new oppportunity window.location = newOpp[0].id; } catch (err) { alert (err.description ); }

 

 

Getting "undifined" error message

 

 

Thanks

 

Jake 

 

Message Edited by jmaskell123 on 09-07-2009 07:56 AM

Hi All,

 

I have created a custom button on the opportunties page called " Renewal 1 Year"

 

https://emea.salesforce.com/006/e?opp3={!Opportunity.Account}%20- Renewal&opp4={!Opportunity.Account}&opp7={!Opportunity.Amount}&opp9={!Opportunity.CloseDate}&opp5=Renewal&opp11=Stocking Order Due&opp14=This is a renewal order

 

it creates a clone of the opportunity with some amendments for a the renewal.

 

how can i get it to add 365 days to the close date ?

 

Sure its somthing simple but i just cant work it out  

 

Thanks

 

Jake 

Message Edited by jmaskell123 on 09-07-2009 03:48 AM

Hi can anyone please help me with this as i have posted it several times with no responce, it is really bugging me as i am so close and i am sure it is something really simple.

I have this code that creates a clone of an opportunity, it is a java script button on the opportuntiy page layout

 

// Copyright 2008 BrightGen Ltd - All Rights Reserved try{ {!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")} // ** EDIT THIS QUERY TO LIST THE FIELDS YOU WANT TO COPY ** var result = sforce.connection.query("Select o.Type, o.StageName, o.Description, o.Amount, o.AccountId From Opportunity o WHERE o.Id = '{!Opportunity.Id}'"); var newOpp = result.getArray("records"); // Reset the Opp Id and reset fields to default values newOpp[0].Id = ''; newOpp[0].Name = "Renewal - {!Opportunity.Name}"; // ** EDIT THESE FIELDS TO SET DEFAULT ANY VALUES ** newOpp[0].StageName = "Prospecting"; newOpp[0].CloseDate = new Date(2099, 0, 1); newOpp[0].Type = "Renewal" var saveResult = sforce.connection.create(newOpp); if (saveResult[0].getBoolean("success")) { newOpp[0].id = saveResult[0].id; alert("Renewal Opportunity Has Been Created."); } else { alert("Failed to create clone: " + saveResult[0]); } // Refresh the page to display the new oppportunity window.location = newOpp[0].id; } catch (err) { alert (err.description ); }

 

but the problem i am having is that this only works when a date is manually imput into the code.

what i want it to do is clone the opportuntiy but for 1 year later.

i think the following line needs to be changed:

 

newOpp[0].StageName = "Prospecting";
newOpp[0].CloseDate = new Date(2099, 0, 1);
newOpp[0].Type = "Renewal"

 

But whatever i put i cannot get it to work

 

Can anyone please help me on this as i am so close to getting a prefect renewal button.

 

Thanks very much to anyone that can help me

 

 

Jake Maskell

Message Edited by jmaskell123 on 09-04-2009 08:13 AM

Hi All,

 

Has anyone come across this before , what is the best way to handle renewal opportunities in saleforce professional .

 

I have seen triggers that automatically create renewal opps when the opp is closed but we unfortunately do not have the Option of triggers and workflows.

 

is there a way to create an s-controll or Visualforce button that when clicked on will create and save a new opportunity for a years time.

 

This would save lots of time for out sales guys and be a big help to our company!!!

 

Any help would greatly appreciated!

 

Thanks A Lot

 

Jake Maskell 

Hi Does anyone know how to edit the following code to add 365 days to the close date of the new opp.

 

The Code i have so far:

try{

{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")}



// ** EDIT THIS QUERY TO LIST THE FIELDS YOU WANT TO COPY **

var result = sforce.connection.query("Select o.Type, o.StageName, o.Description, o.Amount, o.AccountId From Opportunity o WHERE o.Id = '{!Opportunity.Id}'");

var newOpp = result.getArray("records");



// Reset the Opp Id and reset fields to default values

newOpp[0].Id = '';
newOpp[0].Name = "Renewal - {!Opportunity.Name}";

// ** EDIT THESE FIELDS TO SET DEFAULT ANY VALUES **
newOpp[0].StageName = "Prospecting";
newOpp[0].CloseDate = new DATE((TODAY()-CloseDate)+365)
newOpp[0].Type = "Renewal"

var saveResult = sforce.connection.create(newOpp);

if (saveResult[0].getBoolean("success")) {
newOpp[0].id = saveResult[0].id;
alert("Renewal Opportunity Has Been Created.");
}
else {
alert("Failed to create clone: " + saveResult[0]);
}

// Refresh the page to display the new oppportunity
window.location = newOpp[0].id;
}
catch (err) {
alert (err.description );
}

 

But i am getting Undefined message.

 

Thanks if someone can help im sure its somthing simple i must be missing ?

 

 

Kind Regards,

 

Jake


Hi Does anyone know how to edit the following code to add 365 days to the close date of the new opp.


try{ {!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")} // ** EDIT THIS QUERY TO LIST THE FIELDS YOU WANT TO COPY ** var result = sforce.connection.query("Select o.Type, o.StageName, o.Description, o.Amount, o.AccountId From Opportunity o WHERE o.Id = '{!Opportunity.Id}'"); var newOpp = result.getArray("records"); // Reset the Opp Id and reset fields to default values newOpp[0].Id = ''; newOpp[0].Name = "Renewal - {!Opportunity.Name}"; // ** EDIT THESE FIELDS TO SET DEFAULT ANY VALUES ** newOpp[0].StageName = "Prospecting"; newOpp[0].CloseDate = new Date(2099, 0, 1); newOpp[0].Type = "Renewal" var saveResult = sforce.connection.create(newOpp); if (saveResult[0].getBoolean("success")) { newOpp[0].id = saveResult[0].id; alert("Renewal Opportunity Has Been Created."); } else { alert("Failed to create clone: " + saveResult[0]); } // Refresh the page to display the new oppportunity window.location = newOpp[0].id; } catch (err) { alert (err.description ); }

 

I think it needs to be changed on the "
newOpp[0].CloseDate = new Date(2099, 0, 1);

but i dont know how :S 

Thanks if anyone can help as this is important in our company.

Jake

 

is there a way to create an s-control button that creates a new task when clicked on opportunities and contacts. ??????

Hi Does anyone know how to edit the following code to add 365 days to the close date of the new opp.

 

 

// Copyright 2008 BrightGen Ltd - All Rights Reserved try{ {!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")} // ** EDIT THIS QUERY TO LIST THE FIELDS YOU WANT TO COPY ** var result = sforce.connection.query("Select o.Type, o.StageName, o.Description, o.Amount, o.AccountId From Opportunity o WHERE o.Id = '{!Opportunity.Id}'"); var newOpp = result.getArray("records"); // Reset the Opp Id and reset fields to default values newOpp[0].Id = ''; newOpp[0].Name = "Renewal - {!Opportunity.Name}"; // ** EDIT THESE FIELDS TO SET DEFAULT ANY VALUES ** newOpp[0].StageName = "Prospecting"; newOpp[0].CloseDate = new Date(2099, 0, 1); newOpp[0].Type = "Renewal" var saveResult = sforce.connection.create(newOpp); if (saveResult[0].getBoolean("success")) { newOpp[0].id = saveResult[0].id; alert("Renewal Opportunity Has Been Created."); } else { alert("Failed to create clone: " + saveResult[0]); } // Refresh the page to display the new oppportunity window.location = newOpp[0].id; } catch (err) { alert (err.description ); }

 

 

Thanks if anyone can help as this is important in our company.

 

Jake

Message Edited by jmaskell123 on 08-10-2009 03:41 AM

Hi 

 

I am using the following Trigger to create a renewal opportunity for a years time.

 

 

trigger RenewalOpportunity on Opportunity (after update) { for (Integer i = 0; i < Trigger.new.size(); i++) { System.debug('checking opportunity ' + i); System.debug('old.isWon: ' + Trigger.old[i].isWon); System.debug('new.isWon: ' + Trigger.new[i].isWon); if (Trigger.new[i].isWon == true && Trigger.old[i].isWon == false) { Date endDate = Trigger.new[i].CloseDate.addDays(365); System.debug('updating opportunity ' + i); Opportunity renewalOpp = Trigger.new[i].clone(false); renewalOpp.Name = 'Renewal - '+ Trigger.new[i].Name; renewalOpp.closedate = endDate; renewalOpp.stagename = 'D - Relationship Management'; insert renewalOpp; if (Trigger.new[i].Name.startsWith('Renewal - ')) { renewalOpp.Name = Trigger.new[i].Name; update renewalOpp; } System.debug('renewal opportunity inserted' + i); System.debug('renewalOpp.id: ' + renewalOpp.ID); System.debug('TriggerNew[i].id: ' + Trigger.new[i].ID); if (Trigger.new[i].isWon == true && Trigger.old[i].isWon == false) { System.debug('Associating generated opportunity as child of closed->won opportunity'); Opportunity newOpp = [select ID from Opportunity where id = :Trigger.new[i].ID]; newOpp.Renewal_Opportunity__c = renewalOpp.ID; update newOpp; } } } }

Is there a way of edditing the triger so that it is only takes place if a feild on the opportuntiy called " Create Renewal " is ticked.

 

Hope someone can help.

 

Regards

 

Jake 

 

 

Message Edited by jmaskell123 on 08-10-2009 02:37 AM
Message Edited by jmaskell123 on 08-10-2009 02:39 AM

Hi,

 

Is this possible to display in a sidebar component, opportunities for renewal . For example due in 30 , 60 and 90 days with some sort of drop down.

 

the way I can determine if the opportunities are a renewed is because of a customer drown field that called renewal ( options "yes" and "no" )

 

hope this doesn't sound confusing.

 

Many Thanks

 

Jake 

Hi All,

 

Is there a way of creating a button on the opportunities page, that when clicked creates a clone of the opportunity but with a close date of 1 year later , also I would like it to change the Opportunities type to a custom picklist option called "Renewal" and also ad the word Renewal to the end of the opportunity name.

 

I hope someone can help me,

 

sorry im new to this.

 

Thanks

 

Jake 

Hi All,

 

I have created a custom button on the opportunties page called " Renewal 1 Year"

 

https://emea.salesforce.com/006/e?opp3={!Opportunity.Account}%20- Renewal&opp4={!Opportunity.Account}&opp7={!Opportunity.Amount}&opp9={!Opportunity.CloseDate}&opp5=Renewal&opp11=Stocking Order Due&opp14=This is a renewal order

 

it creates a clone of the opportunity with some amendments for a the renewal.

 

how can i get it to add 365 days to the close date ?

 

Sure its somthing simple but i just cant work it out  

 

Thanks

 

Jake 

Message Edited by jmaskell123 on 09-07-2009 03:48 AM

Hi can anyone please help me with this as i have posted it several times with no responce, it is really bugging me as i am so close and i am sure it is something really simple.

I have this code that creates a clone of an opportunity, it is a java script button on the opportuntiy page layout

 

// Copyright 2008 BrightGen Ltd - All Rights Reserved try{ {!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")} // ** EDIT THIS QUERY TO LIST THE FIELDS YOU WANT TO COPY ** var result = sforce.connection.query("Select o.Type, o.StageName, o.Description, o.Amount, o.AccountId From Opportunity o WHERE o.Id = '{!Opportunity.Id}'"); var newOpp = result.getArray("records"); // Reset the Opp Id and reset fields to default values newOpp[0].Id = ''; newOpp[0].Name = "Renewal - {!Opportunity.Name}"; // ** EDIT THESE FIELDS TO SET DEFAULT ANY VALUES ** newOpp[0].StageName = "Prospecting"; newOpp[0].CloseDate = new Date(2099, 0, 1); newOpp[0].Type = "Renewal" var saveResult = sforce.connection.create(newOpp); if (saveResult[0].getBoolean("success")) { newOpp[0].id = saveResult[0].id; alert("Renewal Opportunity Has Been Created."); } else { alert("Failed to create clone: " + saveResult[0]); } // Refresh the page to display the new oppportunity window.location = newOpp[0].id; } catch (err) { alert (err.description ); }

 

but the problem i am having is that this only works when a date is manually imput into the code.

what i want it to do is clone the opportuntiy but for 1 year later.

i think the following line needs to be changed:

 

newOpp[0].StageName = "Prospecting";
newOpp[0].CloseDate = new Date(2099, 0, 1);
newOpp[0].Type = "Renewal"

 

But whatever i put i cannot get it to work

 

Can anyone please help me on this as i am so close to getting a prefect renewal button.

 

Thanks very much to anyone that can help me

 

 

Jake Maskell

Message Edited by jmaskell123 on 09-04-2009 08:13 AM

Hi Does anyone know how to edit the following code to add 365 days to the close date of the new opp.

 

The Code i have so far:

try{

{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")}



// ** EDIT THIS QUERY TO LIST THE FIELDS YOU WANT TO COPY **

var result = sforce.connection.query("Select o.Type, o.StageName, o.Description, o.Amount, o.AccountId From Opportunity o WHERE o.Id = '{!Opportunity.Id}'");

var newOpp = result.getArray("records");



// Reset the Opp Id and reset fields to default values

newOpp[0].Id = '';
newOpp[0].Name = "Renewal - {!Opportunity.Name}";

// ** EDIT THESE FIELDS TO SET DEFAULT ANY VALUES **
newOpp[0].StageName = "Prospecting";
newOpp[0].CloseDate = new DATE((TODAY()-CloseDate)+365)
newOpp[0].Type = "Renewal"

var saveResult = sforce.connection.create(newOpp);

if (saveResult[0].getBoolean("success")) {
newOpp[0].id = saveResult[0].id;
alert("Renewal Opportunity Has Been Created.");
}
else {
alert("Failed to create clone: " + saveResult[0]);
}

// Refresh the page to display the new oppportunity
window.location = newOpp[0].id;
}
catch (err) {
alert (err.description );
}

 

But i am getting Undefined message.

 

Thanks if someone can help im sure its somthing simple i must be missing ?

 

 

Kind Regards,

 

Jake


Hi Does anyone know how to edit the following code to add 365 days to the close date of the new opp.

 

 

// Copyright 2008 BrightGen Ltd - All Rights Reserved try{ {!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")} // ** EDIT THIS QUERY TO LIST THE FIELDS YOU WANT TO COPY ** var result = sforce.connection.query("Select o.Type, o.StageName, o.Description, o.Amount, o.AccountId From Opportunity o WHERE o.Id = '{!Opportunity.Id}'"); var newOpp = result.getArray("records"); // Reset the Opp Id and reset fields to default values newOpp[0].Id = ''; newOpp[0].Name = "Renewal - {!Opportunity.Name}"; // ** EDIT THESE FIELDS TO SET DEFAULT ANY VALUES ** newOpp[0].StageName = "Prospecting"; newOpp[0].CloseDate = new Date(2099, 0, 1); newOpp[0].Type = "Renewal" var saveResult = sforce.connection.create(newOpp); if (saveResult[0].getBoolean("success")) { newOpp[0].id = saveResult[0].id; alert("Renewal Opportunity Has Been Created."); } else { alert("Failed to create clone: " + saveResult[0]); } // Refresh the page to display the new oppportunity window.location = newOpp[0].id; } catch (err) { alert (err.description ); }

 

 

Thanks if anyone can help as this is important in our company.

 

Jake

Message Edited by jmaskell123 on 08-10-2009 03:41 AM

As discussed in Ideas (http://ideas.salesforce.com/article/show/69729) here's a solution we have used for clients to enable customisation of the Clone button on Opportunities. This can be used to selectively choose which fields to copy and set default values:

 

For full details and the code to clone opportunity Line Items please contact me directly. We will be re-writing this in VisualForce over the coming months to make it futureproof.

 

Steps to Implement - Admins only

1. Setup -> Customize -> Opportunity -> Buttons and Links

2. Create new custom button called Clone, behaviour is Execute Javascript, Display Type Detail Page Button.

3. Paste in the code below and edit to match your requirements.

4. Remember to add the new button to the Opportunity page layout(s) and hide the original Clone button.

4. Test!

 

// Copyright 2008 BrightGen Ltd - All Rights Reserved try{ {!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")} // ** EDIT THIS QUERY TO LIST THE FIELDS YOU WANT TO COPY ** var result = sforce.connection.query("Select o.Type, o.StageName, o.Product_Type__c, o.Planned_Opportunity__c, o.MarketSector__c, o.CampaignId, o.Business_Unit__c, o.Amount, o.AccountId From Opportunity o WHERE o.Id = '{!Opportunity.Id}'"); var newOpp = result.getArray("records"); // Reset the Opp Id and reset fields to default values newOpp[0].Id = ''; newOpp[0].Name = "Clone {!Opportunity.Name}"; // ** EDIT THESE FIELDS TO SET DEFAULT ANY VALUES ** newOpp[0].StageName = "1. Prospecting"; newOpp[0].CloseDate = new Date(2099, 0, 1); var saveResult = sforce.connection.create(newOpp); if (saveResult[0].getBoolean("success")) { newOpp[0].id = saveResult[0].id; alert("Opportunity cloned without line items"); } else { alert("Failed to create clone: " + saveResult[0]); } // Refresh the page to display the new oppportunity window.location = newOpp[0].id; } catch (err) { alert (err.description ); }

 

 
Message Edited by bg_richard on 02-05-2009 07:11 AM
Hi,

 I want to assign an datetime field value to another datetime field.
 I tried the following ways, any help on this highly appreciated.

1. var day1 = Day( {!Event.StartDateTime} );
    var month1 = Month( {!Event.StartDateTime} );
    var year1 = Year( {!Event.StartDateTime} );
    var time = {!Event.StartDateTime}.getTime();
    var myDate = new Date(year1, month1, day1 time);
    var endDate = new Date(year1, month1, day1 time);

2. var myDate = new Date("yyyy-mm-dd HH:MM:SS");
    myDate = "2013-06-15T14:50:30Z";
    myDate = '{!Event.StartDateTime}';

3. var dateVar = new Date("2013-06-15T14:50:30Z");
    dateVar = '{!Event.StartDateTime}';

Any suggestions?