You need to sign in to do that
Don't have an account?
Kondal Rao learner
urgent pls
HI experts,
There is deal custom object and opporunity standard i created one button name called convert in deal object so when user click on that deal objects what ever are there it has covert in to opportunity so my requriment is now only approved deal has to convert opportuntiy so give me idea on this pls.
Hi Aditya,
Please mark this post as solved. It will help other
All Answers
Hi Aditya,
you can have a button of type visualforcepage. on that page you can query the deal object and check if the status of the deal is convert or not and if it is then you can map the opportunity field with deal field. I will explain this with an example
1. create a button on deal
2. select display type as detail page button
3. select content source as visualforce page
4. <apex:page standardcontroller="deal__c" extensions="deal_controller" action="{!convert}">
</apex:page>
5. public class deal_controller{
deal__c dlc;
public deal_controller(ApexPages.StandardController stdController){
dlc = (deal__c)stdController.getRecord();
dlc = [select id,name,customefields__c,status from deal__c where id=: dlc.Id];
}
public pagereference convert(){
if(dlc.status == "Convert'){
Opprotunity opp = new Opportunity();
opp.Name = dlc.Name;
opp.customfield__c = dlc.customfields__c;
insert opp;
}
}
}
Hope this will help you.
If it works for you please mark it as solution and also click on start to give some KUDOS
hi amit ,
thanks for reply so there is button alredy name called button on deal object so my requirment is that when status approved at the time only deal has to convert into opportunity thats it, there will be other status like approved ,approval pending , rejected
sorry i forgot to give my vf page and apex class pls add ur code to this one so that i can understand pls
Apex class:
public with sharing class MyDealControllerExtension {
public ApexPages.StandardController CONTROL;
public MyDealControllerExtension(ApexPages.StandardController stdController) {
this.CONTROL = stdController;
}
public pageReference doCreateOpportunity() {
Opportunity newOpp = new Opportunity();
Deal__c Deal = [select Id, Name, Distributor__c, End_Customer__c, Industry__c, Partner_Specializations__c,Partner_Tier__c,Product_Category__c,Segment__c from Deal__c where id = :CONTROL.getId()];
// add your field mappings here
newOpp.Name = Deal.Name;
newOpp.stagename = 'Negotiation/Review';
newOpp.CloseDate= system.today()+30;
// etc.
insert newOpp;
pageReference p = new pageReference('/' + newOpp.id);
p.setRedirect(true);
return p;
}
Visualforce page:
<apex:page standardController="Deal__c" extensions="MyDealControllerExtension" action="{!doCreateOpportunity}" />
Hi Adity your code looks fine i have added if condition to your code for status. My changes are in red
Apex class:
public with sharing class MyDealControllerExtension {
public ApexPages.StandardController CONTROL;
public MyDealControllerExtension(ApexPages.StandardController stdController) {
this.CONTROL = stdController;
}
public pageReference doCreateOpportunity() {
Opportunity newOpp = new Opportunity();
Deal__c Deal = [select Id, Name, Distributor__c, End_Customer__c, Industry__c, Partner_Specializations__c,Partner_Tier__c,Product_Category__c,Segment__c from Deal__c where id = :CONTROL.getId()];
// add your field mappings here
if(Deal.status == "Convert'){ // make sure you fetch status field in above query
newOpp.Name = Deal.Name;
newOpp.stagename = 'Negotiation/Review';
newOpp.CloseDate= system.today()+30;
// etc.
insert newOpp;
}
pageReference p ;
if(newOpp.id != null){
p= new pageReference('/' + newOpp.id);
}else{
p= new pageReference('/' + Deal.id);
}
p.setRedirect(true);
return p;
}
Visualforce page:
<apex:page standardController="Deal__c" extensions="MyDealControllerExtension" action="{!doCreateOpportunity}" />
hey thanks for and i have one more problem yaar pls do it
i have custom object called deal and standard object called oppotuntiy i created button called convert when i click on that deal has to convert in to opporuntiy its working fine now but my requirement is that
public ApexPages.StandardController CONTROL;
public MyDealControllerExtension(ApexPages.StandardController stdController) {
this.CONTROL = stdController;
}
public pageReference doCreateOpportunity() {
Opportunity newOpp = new Opportunity();
Deal__c Deal = [select Id, Name, Distributor__c, End_Customer__c, Industry__c, Partner_Specializations__c,Partner_Tier__c,Product_Category__c,Segment__c from Deal__c where id = :CONTROL.getId()];
// add your field mappings here
newOpp.Name = Deal.Name;
newOpp.stagename = 'Negotiation/Review';
newOpp.CloseDate= system.today()+30;
Deal.Deal_Status__c = 'Converted';
// etc.
insert newOpp;
pageReference p = new pageReference('/' + newOpp.id);
p.setRedirect(true);
return p;
}
Hi Aditya,
Please mark this post as solved. It will help other