You need to sign in to do that
Don't have an account?

Need urgent help regarding tigger VF Extension class through custom button
Hi All,
I'm haveing scenario like Custom button on opportunity details page.Once we click on the buttom need to validate opportunity stage as prospecting if not error should throws on detils page if yes create a new contract with prepopulated info on the contract and contract information should show on detail page.
Wating for help.
if you want to create new contract and not updaye an existijg contract then just use the url that appears when you click new button on contract tab...
All Answers
Hi,
I tried above scenario as created custom button in opportunity detials page and create a dummy VF page and Extension class
Now i assigned VF page to custom button and now i stuck at extension class like how to validate the opportunity stage is prosprecting and show error mesage once if not prospecting need to show the contract edit view with existing info and then save.
Can any one help with logic pls........
an example using js: {!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")} var opportunitystage= '{!Opportunity.StageName}'; if(opportunitystage == 'prospecting') alert('stage is not prospecting'); else window.open('https://ap1.salesforce.com/80090000000PwZT/e?retURL=%2F80090000000PwZT');
80090000000PwZT is the contract id,,, put this dynamically....
Hi same thing i had doen with useing VF page and extension class as below
<apex:page standardController="Opportunity" extensions="CreateRoutineContractExtension" action="{!redirect}">
<apex:pageMessages />
</apex:page>
extension calss:
public with Sharing class CreateRoutineContractExtension {
Opportunity opp = new Opportunity();//Variable to store opportunity ids
public CreateRoutineContractExtension(ApexPages.StandardController controller) {
}
public PageReference redirect(){
PageReference pageRef;
id OpportuityId=ApexPages.currentPage().getParameters().get('id');
System.debug('------------'+OpportuityId);
opp = [Select Id,Name,StageName from Opportunity where Id =:OpportuityId];
if(opp.StageName=='Closed Won'){
apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'Opportuity stage with Closed won user unable to create a new contract:' );
apexpages.addmessage(msg);
}
else{
pageRef = new PageReference('https://na15.salesforce.com/800/e?retURL=%2F800%2Fo');
}
return pageRef;
}
}
To make the URL as dynamic do i need to URL methods.
pls code sample.
prepare your URL as string an then use it in page reference object....
for example:
string contractID = 80090000000PwZ;
string myURL = 'https://ap1.salesforce.com/'+contractID +'/e?retURL=%2F'+contractID ;
pageRef = new PageReference(myURL)
your myurl will depend on your contractID and hence will open the edit page for that contract....
I had doen in below way like
String dynrecordurl = URL.getSalesforceBaseUrl().toExternalForm() + '/' + opp.Id;
pageRef = new PageReference(dynrecordurl);//URL for contract edit page
but here what happens if opportunity stagename is not equal to Closed won it is redirecting to corresponding opportunity detail page.
But my requriment is it should redirect to contract edit page with prepopulated values so that user can fill contract details and save file.
Here we are createing the contract and not updateing the contract.
just edit any contract in your org and use the url that appears in the browser, you just need to put the contract id dynamically as i have done in below example,.....
string contractID = 80090000000PwZ;
string myURL = 'https://ap1.salesforce.com/'+contractID +'/e?retURL=%2F'+contractID ;
pageRef = new PageReference(myURL)
if you want to create new contract and not updaye an existijg contract then just use the url that appears when you click new button on contract tab...
thanks for reply.
I had question like
string contractID = 80090000000PwZ;(this contract id is id of a contract which is already created in salesforce) if yes in my case i just want a freash contract edit page to enter data and insert to database.and not the already created contract (I dont want to update ht e contract in database).
Is i'm confuseing you.....are i'm clear....
Yes thanks buddy....
to populate default values in fields, you will have to pass the field values in the url,,,
fieldid='value you want'
field id :you can get from set up..
all the details are in this post...
http://raydehler.com/cloud/clod/salesforce-url-hacking-to-prepopulate-fields-on-a-standard-page-layout.html
you have to pass the fields value(that you need to autopopulate)..
fieldsid = 'yourvalue'