• RSButtar
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 1
    Replies

I have to Add Product Records from a Custom Package_Product__c Object that has lookup to Product2, into the Product Related list on Opportunity Detail Page 

I have Custom Link on the Opportunity Detail Page. This link Opens a VF Page with Drop downlist that contains records from a CUstom Object Package_Header__c (). Each Package have more than one records from the custom object Package_Products__c. When a user select the package from the Dropdown, all the products in the package are added to the Product Related List on the Opprotunity detail page.

I have completed the first part here, where I have inserted the Records Package_Header__c Records into the dropdown on the basis of Legal_entity__c field (it represent countries). Also I have queried the records from the custom Object Package_Products__c. But My main Problem is how to insert the records into Product Related List (This related list is Standard one and comes by default with every opportunity record and lists the products associated with the opportunity)

The coded for it is written below: I am using Extension = packageSelectionController  and Opportunity as Standard Controller

 

public class packageSelectionController {

public string legalEntity;

public Opportunity opp = new Opportunity();

public Package_Header__c pobj = new Package_Header__c();

public List<Package_Header__c> plist {get;set;}

 

public packageSelectionController(ApexPages.StandardController controller) {

String id = ApexPages.currentPage().getParameters().get('id'); opp = [

select Legal_Entity__c from Opportunity where id = :id];

legalEntity = opp.Legal_Entity__c;

plist = [select id, Name from Package_Header__c where Legal_Entity__c =: legalEntity];

}

 

//Create the picklist on the VF Page and populate it withy the records from Package_Header__c

String piValues;

public List<SelectOption> getItems(){

List<SelectOption> options = new List<SelectOption>();options.add(

new SelectOption(' ',' ')); for(Package_Header__c pobj1: plist)

{

options.add(new SelectOption(pobj1.id,pobj1.Name));

}

return options;

}

 

public String getPiValues(){ return piValues;

}

public void setPiValues(String selectedValue){ this.piValues = selectedValue;

}

 

public String getLegalEntity(){ return legalEntity;

}

//create a list of package products that holds the products for a particular package,(used in the SelectPackage method below)

public List<Package_Product__c> packageProduct = new List<Package_Product__c>();

public List<OpportunityLineItem> oplItem = new List<OpportunityLineItem>();

public PageReference SelectPackage(){

//Select the Required fields from the Package_Product__c Onthe basis of selected value of the picklist for Packages

String packageId = ApexPages.currentPage().getParameters().get(piValues);

packageProduct = [Select Id, Name, Quantity__c, Product2__c, Discount__c, Fixed_Price_Discount__c,

Sort_Order__c, Opt__c, Smpl__c, Product2__r.Id, Product2__r.ProductCode From Package_Product__c

Where Package_Header__c = :packageId ];

//variables for holding then field values from the

String productName;

String productCode;

String quantity;

String discount;

String fixedPrice;

String Opt;

 

//For loop for assigning the retieved values for each record in the above query to the variables declared above.

 for(Package_Product__c pkProd: packageProduct){oplItem.productName = packageProduct.Name;

oplItem.discount = packageProduct.Discount__c;

}

 

PageReference opportunityPage = new ApexPages.StandardController(opp).view();

opportunityPage.setRedirect(true);

return opportunityPage;

 

}

 

public PageReference cancel() {PageReference opportunityPage = new ApexPages.StandardController(opp).view();

opportunityPage.setRedirect(true);

return opportunityPage;

}

}

 

<!--  Code for Page -->

<apex:page standardController="Opportunity" extensions="packageSelectionController" tabStyle="Opportunity" sidebar="false" showHeader="true"  >
  <!-- Begin Default Content REMOVE THIS -->

  <apex:form >
 
  <div style="border: 1px solid red; padding-top:10px; padding-bottom:10px;">
  <apex:pageBlock rendered="true" title="You are Logged in as: {!$User.FirstName} {!$User.LastName}" >
 
  <apex:outputLabel value="Select Product Package from List: " for="packageList" style="font-family:Arial,Sans-Serif; line-height:10pt; font-size:11pt; margin-right:10px; "/><br/>
      <!-- This value parameter takes the name of the list -- getRequestTypeItems (without get) of type Select Options -->
    <br/>
  <apex:selectList value="{!piValues}" size="1">
      <apex:selectOptions value="{!items}"></apex:selectOptions>
  </apex:selectList>
 
 <br/>
 
 <apex:commandButton title="Select" value="Select" action="{!SelectPackage}"/>
 <apex:commandButton title="Cancle" value="Cancel" action="{!cancel}"/>
  </apex:pageBlock>
  </div>
  </apex:form>
  <!-- End Default Content REMOVE THIS -->
</apex:page>

I am designing a VF Page for force.com sites This page is actually a Form to be filled by te user for submitting queries.

Before storing the Contact Record that the user enter in the form, I have to check weather the Email entered by the user already exist. If it exist, then just case will be created and it will be linked with the existing Contact having the same Email Id that the user entered. If the Email entered by the user doesn't exist, I have to create both the Contact and the Case. I need to wriete the logic with in my Apex Class and don't need the trigger for it. I have completed this second part, but don't know how to implement the first one. The code for this second part that creates both the contacts and case without checking the Email is listed below:

 

public class TechnicalServiceController { public String companyName{set; get;}

public String firstName{set; get;}

public String lastName{set; get;}

public String title{set; get;}

public String phoneNumber{set; get;}

public String emailId{set; get;}

public String department{set; get;}

public String firstAddress{set; get;}

public String secondAddress{set; get;}

public String cityOrTown{set; get;}

public String state{set; get;}

public String postalCode{set; get;}

public String country{set; get;} public String typeOfRequest{set; get;}

 

//Fields that goes only to the Case Record

 public String catalogNumber{set; get;}

public String lotNumber{set; get;}

public String productName{set; get;} public String queryBox{set; get;}

 

//This is the code where I am trying to search for Duplicate Records.

List<Contact> oldContacts = [Select Email From Contact];

{ // Can't understand WHY I NEED This Bracket here. If I don't give it, It will give me the error -

//Error: Compile Error: expecting right curly bracket, found 'for' at line 60 column 4

 for(Contact c : oldContacts){ if(c.Email != emailId)

//Here I have to call the method -- public PageReference saveRecords() written below, to save the Contact

//Information if duplicate Email Doesn't exist

saveRecords();//This gives me the error -- System.Exception: DML currently not allowed.

}

}

 

public PageReference saveRecords() {

try

{

Contact contactToStore = new Contact();

contactToStore.FirstName = firstName;

contactToStore.LastName = lastName;

contactToStore.Phone = phoneNumber;

contactToStore.Email = emailId;

contactToStore.MailingStreet = firstAddress;

contactToStore.MailingCity = cityOrTown;

contactToStore.MailingState = state;

contactToStore.MailingPostalCode = postalCode;

contactToStore.MailingCountry = String.valueOf(country);

insert contactToStore;

 

//new Object of type Account Standard Object Account accountToCreate = new Account();

accountToCreate.Legal_Entity__c = String.valueOf(country);

accountToCreate.Name = companyName;

accountToCreate.PostalCode__c = postalCode;

accountToCreate.Name = companyName; insert accountToCreate;

 

Contact tempContact = [Select id from Contact Where id =: contactToStore.Id]; Account tempAccount = [Select id from Account Where id =: accountToCreate.Id];

//new Object of type Case Standard Object

Case caseToCreate = new Case();

caseToCreate.ContactId = contactToStore.id;

caseToCreate.AccountId = tempAccount.id;

caseToCreate.Subject = 'This is the Web To Case';

caseToCreate.Serial_Number__c = catalogNumber;

caseToCreate.Lot_Number__c = lotNumber;

caseToCreate.Product_Code__c = productName;

caseToCreate.Description = queryBox;

insert caseToCreate;

 

return null;

}

 

catch(Exception e)

{

ApexPages.addMessages(e);

return null;

}

 

}

 

 

I have main problem with the following section of the code from above:

//This is the code where I am trying to search for Duplicate Records.

List<Contact> oldContacts = [Select Email From Contact];

{ // Can't understand WHY I NEED This Bracket here. If I don't give it, It will give me the error -

//Error: Compile Error: expecting right curly bracket, found 'for' at line 60 column 4 -- Can anyone tell me why I need this bracket  //here

 for(Contact c : oldContacts){ if(c.Email != emailId)

//Here I have to call the method -- public PageReference saveRecords() written ABOVE, to save the Contact

//Information if duplicate Email Doesn't exist

saveRecords();//This gives me the error -- System.Exception: DML currently not allowed.

}

}

 

Is there anyone who can help me to search for duplicate Email record and save the contact detail if email record don't exists.

I am designing a VF Page for force.com sites This page is actually a Form to be filled by te user for submitting queries.

Before storing the Contact Record that the user enter in the form, I have to check weather the Email entered by the user already exist. If it exist, then just case will be created and it will be linked with the existing Contact having the same Email Id that the user entered. If the Email entered by the user doesn't exist, I have to create both the Contact and the Case. I need to wriete the logic with in my Apex Class and don't need the trigger for it. I have completed this second part, but don't know how to implement the first one. The code for this second part that creates both the contacts and case without checking the Email is listed below:

 

public class TechnicalServiceController { public String companyName{set; get;}

public String firstName{set; get;}

public String lastName{set; get;}

public String title{set; get;}

public String phoneNumber{set; get;}

public String emailId{set; get;}

public String department{set; get;}

public String firstAddress{set; get;}

public String secondAddress{set; get;}

public String cityOrTown{set; get;}

public String state{set; get;}

public String postalCode{set; get;}

public String country{set; get;} public String typeOfRequest{set; get;}

 

//Fields that goes only to the Case Record

 public String catalogNumber{set; get;}

public String lotNumber{set; get;}

public String productName{set; get;} public String queryBox{set; get;}

 

//This is the code where I am trying to search for Duplicate Records.

List<Contact> oldContacts = [Select Email From Contact];

{ // Can't understand WHY I NEED This Bracket here. If I don't give it, It will give me the error -

//Error: Compile Error: expecting right curly bracket, found 'for' at line 60 column 4

 for(Contact c : oldContacts){ if(c.Email != emailId)

//Here I have to call the method -- public PageReference saveRecords() written below, to save the Contact

//Information if duplicate Email Doesn't exist

saveRecords();//This gives me the error -- System.Exception: DML currently not allowed.

}

}

 

public PageReference saveRecords() {

try

{

Contact contactToStore = new Contact();

contactToStore.FirstName = firstName;

contactToStore.LastName = lastName;

contactToStore.Phone = phoneNumber;

contactToStore.Email = emailId;

contactToStore.MailingStreet = firstAddress;

contactToStore.MailingCity = cityOrTown;

contactToStore.MailingState = state;

contactToStore.MailingPostalCode = postalCode;

contactToStore.MailingCountry = String.valueOf(country);

insert contactToStore;

 

//new Object of type Account Standard Object Account accountToCreate = new Account();

accountToCreate.Legal_Entity__c = String.valueOf(country);

accountToCreate.Name = companyName;

accountToCreate.PostalCode__c = postalCode;

accountToCreate.Name = companyName; insert accountToCreate;

 

Contact tempContact = [Select id from Contact Where id =: contactToStore.Id]; Account tempAccount = [Select id from Account Where id =: accountToCreate.Id];

//new Object of type Case Standard Object

Case caseToCreate = new Case();

caseToCreate.ContactId = contactToStore.id;

caseToCreate.AccountId = tempAccount.id;

caseToCreate.Subject = 'This is the Web To Case';

caseToCreate.Serial_Number__c = catalogNumber;

caseToCreate.Lot_Number__c = lotNumber;

caseToCreate.Product_Code__c = productName;

caseToCreate.Description = queryBox;

insert caseToCreate;

 

return null;

}

 

catch(Exception e)

{

ApexPages.addMessages(e);

return null;

}

 

}

 

 

I have main problem with the following section of the code from above:

//This is the code where I am trying to search for Duplicate Records.

List<Contact> oldContacts = [Select Email From Contact];

{ // Can't understand WHY I NEED This Bracket here. If I don't give it, It will give me the error -

//Error: Compile Error: expecting right curly bracket, found 'for' at line 60 column 4 -- Can anyone tell me why I need this bracket  //here

 for(Contact c : oldContacts){ if(c.Email != emailId)

//Here I have to call the method -- public PageReference saveRecords() written ABOVE, to save the Contact

//Information if duplicate Email Doesn't exist

saveRecords();//This gives me the error -- System.Exception: DML currently not allowed.

}

}

 

Is there anyone who can help me to search for duplicate Email record and save the contact detail if email record don't exists.


I am creating a public Web form in Visual Force for the Force.com site. The user is not logged in. When he fill the form and click the submit button,  the form will create the a contact and Account records (under Contact and Account Standard object), and create a case for that contact(under case standard object).

 

I am able to create the contact but not able to create and  insert the case for that contact.

 

The controller code I  am using is listed below:

 

public class TechnicalServiceController {
   
    public String companyName{set; get;}
    public String firstName{set; get;}
    public String lastName{set; get;}
    public String title{set; get;}
    public String phoneNumber{set; get;}
    public String emailId{set; get;}
    public String department{set; get;}
    public String firstAddress{set; get;}
    public String secondAddress{set; get;}
    public String cityOrTown{set; get;}
    public String state{set; get;}
    public String postalCode{set; get;}
    public String country{set; get;}
    public String typeOfRequest{set; get;}

 

 public PageReference saveRecords() {
           
       try
       {
       Contact contactToStore = new Contact();
           contactToStore.FirstName = firstName;
           contactToStore.LastName = lastName;
           contactToStore.Phone = phoneNumber;
           contactToStore.Email = emailId;
           contactToStore.MailingCountry = String.valueOf(country);
           insert contactToStore;
  

//new Object of type Account Standard Object    

 Account accountToCreate = new Account();
           accountToCreate.Name = companyName;
           insert accountToCreate;
            
           
      //new Object of type Case Standard Object
      Case caseToCreate = new Case();                     //don't know how to go onward from here. getting error here
            caseToCreate.Contact = contactToStore.lastName;    

            caseToCreate.Account = companyName;       
           return null;        
        }
        catch(Exception e)
            {
            ApexPages.addMessages(e);
            return null;
            } 

 

For the code block ab ove:

 

Contact and Account are Lookupfields on Case record  but in my controller/webpage these are text fields and I am trying to store these text fields in the above 2 lookup fields

when I try to store them in the corrresponding fields on the case, it gives me following error message:
Error: Illegal assignment from String to SOBJECT

Is there anyone who can help me on it. I am not using Web to case because in that case I have to display
the fields from my case object on the web page which is not required as some fields are picklist on my webpage and they
are stored as text on case object record.

 

Also I need to insert the Contact and Case Related List on the Account Record; And Cased Related list in the Contact record for the corresponding Account, Contact , and Case  I create.

 

 

Is there anyone who can please help me on this...!!!!


I am creating a public Web form in Visual Force for the Force.com site. The user is not logged in. When he fill the form and click the submit button,  the form will create the a contact and Account records (under Contact and Account Standard object), and create a case for that contact(under case standard object).

 

I am able to create the contact but not able to create and  insert the case for that contact.

 

The controller code I  am using is listed below:

 

public class TechnicalServiceController {
   
    public String companyName{set; get;}
    public String firstName{set; get;}
    public String lastName{set; get;}
    public String title{set; get;}
    public String phoneNumber{set; get;}
    public String emailId{set; get;}
    public String department{set; get;}
    public String firstAddress{set; get;}
    public String secondAddress{set; get;}
    public String cityOrTown{set; get;}
    public String state{set; get;}
    public String postalCode{set; get;}
    public String country{set; get;}
    public String typeOfRequest{set; get;}

 

 public PageReference saveRecords() {
           
       try
       {
       Contact contactToStore = new Contact();
           contactToStore.FirstName = firstName;
           contactToStore.LastName = lastName;
           contactToStore.Phone = phoneNumber;
           contactToStore.Email = emailId;
           contactToStore.MailingCountry = String.valueOf(country);
           insert contactToStore;
  

//new Object of type Account Standard Object    

 Account accountToCreate = new Account();
           accountToCreate.Name = companyName;
           insert accountToCreate;
            
           
      //new Object of type Case Standard Object
      Case caseToCreate = new Case();                     //don't know how to go onward from here. getting error here
            caseToCreate.Contact = contactToStore.lastName;    

            caseToCreate.Account = companyName;       
           return null;        
        }
        catch(Exception e)
            {
            ApexPages.addMessages(e);
            return null;
            } 

 

For the code block ab ove:

 

Contact and Account are Lookupfields on Case record  but in my controller/webpage these are text fields and I am trying to store these text fields in the above 2 lookup fields

when I try to store them in the corrresponding fields on the case, it gives me following error message:
Error: Illegal assignment from String to SOBJECT

Is there anyone who can help me on it. I am not using Web to case because in that case I have to display
the fields from my case object on the web page which is not required as some fields are picklist on my webpage and they
are stored as text on case object record.

 

Also I need to insert the Contact and Case Related List on the Account Record; And Cased Related list in the Contact record for the corresponding Account, Contact , and Case  I create.

 

 

Is there anyone who can please help me on this...!!!!