• Janet Guo
  • NEWBIE
  • 80 Points
  • Member since 2012

  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 21
    Replies

Greetings to everyone!

Here is a question. My APEX controller:

 

public class Fullfunctionality_2 {
 
   private List<Item__c> items;
   private String sortDirection = 'ASC';
   private String sortExp = 'name';
   private String searchStr = ' order by ';
   public Date searchDateCopy;
   public String searchTextCopy;
   public Boolean EndSearch { get; set; }
   public Boolean DelCopy { get; set; }
   public Boolean MakeCopy { get; set; }
   public String NewItemName {get; set;}
   public Integer NewItemQuantity { get; set; }
   public Integer NewItemPrice { get; set; }
   public String NewItemType { get; set; }
   public Date NewItemReleaseDate { get; set; }
   public String IdToDel { get; set; }
   public String searchText {get;set;}
   public Date searchDate { get; set; }
   public List<Item__c> searchResults {get;set;}
   
   public fullfunctionality_2() {

       ViewData();
   }

   public List<SelectOption> getTypes(){
       List<SelectOption> types = new List<SelectOption>();
       Schema.DescribeFieldResult fieldResult = Item__c.Item_Type__c.getDescribe();
       List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
       for( Schema.PicklistEntry f : ple)
           {
              types.add(new SelectOption(f.getLabel(), f.getValue()));
           }       
       return types;
    }
    
   public PageReference add(){

        Item__c NewItem = new Item__c(            
                Name = NewItemName,
                Item_Price__c = NewItemPrice,
                Items_Available__c = NewItemQuantity,
                Item_Type__c = NewItemType,
                Release_Date__c = NewItemReleaseDate
                );
                insert NewItem; 
                ViewData();
                PageReference curPage = ApexPages.currentPage(); 
                curPage.getParameters().put('success','true');
                curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
                curPage.setRedirect(true);
                NewItemName=null;
                NewItemQuantity=null;
                NewItemPrice = null;
                NewItemReleaseDate = null;
                return null; 
    }     
   public PageReference del() {

        Item__c ItemToDel = [SELECT id
                             FROM Item__c
                             WHERE id = :IdToDel];
        delete ItemToDel;   
               
        PageReference curPage = ApexPages.currentPage(); 
        curPage.getParameters().put('success','true');
        curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
        ViewData();     
        return curPage;          
    }    

   public String sortExpression
   {
     get
     {
        return sortExp;
     }
     set
     {
       if (value == sortExp)
         sortDirection = (sortDirection == 'ASC')? 'DESC' : 'ASC';
       else
         sortDirection = 'ASC';
       sortExp = value;
     }
   }

 public String getSortDirection()
 {
    if (sortExpression == null || sortExpression == '')
      return 'ASC';
    else
     return sortDirection;
 }

 public void setSortDirection(String value)
 {  
   sortDirection = value;
 }
  
   public List<Item__c> getItems() {
       return items;
   }

   public PageReference ViewData() {
       if (DelCopy == true){
           searchDateCopy = null;
           searchTextCopy = null;}

       if (MakeCopy == true) {
           searchDateCopy = searchDate;
           searchTextCopy = searchText;
       }    
       string sortFullExp = sortExpression  + ' ' + sortDirection;
       if(searchTextCopy != null) {
           searchstr = 'WHERE Name LIKE \'%' + searchTextCopy + '%\' order by ';}
       if(searchDateCopy != null) {
           searchstr = 'WHERE Name LIKE \'%' + searchTextCopy + '%\' and DAY_ONLY(CreatedDate) =:searchdatecopy order by ';}   
           
       items = Database.query('Select id, Name, Item_Price__c, CreatedDate from Item__c ' + searchstr + sortFullExp);
       

           searchText = null;
           searchDate = null;

       return null;
   }
}

 And here is a test class for controller:

 

@isTest
private class TestFullFunctionality_2 {

String NewItemName = 'NEWITEM';
Integer NewItemPrice = 100;
String NewItemType = 'Solid';
Integer NewItemQuantity = 10;

static testMethod void testAdd() {
TestFullFunctionality_2 ext;       
Item__c NewItem = new Item__c(name = 'NEWITEM', Item_Price__c = 100, Item_Type__c = 'Solid', Items_Available__c = 10 );
insert NewItem;
FullFunctionality_2 Con=new FullFunctionality_2();
Con.add();
Con.del();
Con.viewData();

}
}

 I still cannot understand - why do i get an error:

 

System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Item_Price__c]: [Item_Price__c]

 Maybe someone can help me?

 

Thanks in advance.

Hello,

 

Are there any APIs that salesforce provide to get list of Companies, Accounts and Contacts that we can use in customController in APEX code.

 

I am a newbie to salesforce development, so please provide the detail or any link about SalesforceAPIs.

 

Thanks.

How to retrieve the account fields from the query [SELECT Accoun.Id,Account.Name FROM Contact Limit 5] in a class.

The code is shown below...

public class Retrieving_Fields {
public List<Contact> con{set;get;}
public void RetrievingFields(){
con=[SELECT Account.Id,Account.Name,Account.Phone FROM Contact LIMIT 5];
System.debug(con);
}
}

please hlelp me out how to retrieve those fields from the above class

hi,

 

iam new to salesforce and i need help to add some values , which should be retrived from 3 textfields and it should be displayed in another text field.

 

for E.g.,

 

i have 3 text field

 

1. X-ray fees

2. E.C.G fees

3.Indoor Injection fees

 

I) i have to retive the values from these textboxes 

II) add these values 

III) display the added values in another txt box (Say) Total Fees

 

and i don't have idea how to implement this one using formulas..

Hi,

 

iam new to salesforce and have been learning for past 1 month. i wonder how to create dependency field for textbox.

 

 

for example:  i have a picklist with 2 values 

                          1.Nurse

                          2.Doctor

 

If i choose doctor 

 

following textfields should be active.

 

1.operation details

2.patient to operate on

3.type of operation etc,..

 

can anyone explain me clearly, to understand it easily

 

Hello, I have a trigger that is working on the Before Update, but is not working on Before Insert.

The idea is that when a Task is Inserted or Updated,

If the purpose__c = 'Sway Card, and Owner.Userrole contains 'BDM',

then set account.type = 'Suspect'

 

So as you can see it updates the Account Object, not sure if that has anything to do with it. Also purpose__c is a multi-picklist field. 

 

Anybody can help me out?

 

My code is here:  

 

trigger Task_SWayCard on Task (before insert, before update) {

List<ID> accID = new List<ID>(); //AccountIDs in the trigger
List<ID> ownerID = new List<ID>(); //Task Owners in the Trigger
for (task t : trigger.new)
{
If ( t.purpose__c == 'Sway Cards' )
{accID.add(t.AccountID);}
ownerID.add(t.ownerID);
}

If (accID != null)
{
list<Account> acc = [select id, name, ownerID, type from Account where Id =: accID]; //Accounts from the AccID list
List<User> owner = [select id, name, userrole.name from User where Id =: ownerID]; //Users from the ownerID list
List<User> bdmOwner = [select id, name, userrole.name from user where Id =: owner //Users where name like BDM
and userrole.name like '%BDM'];

List<Account> accToUpdate = [select id, name, type, ownerID from account where ownerID =:bdmOwner
and id =:acc];  //Selects the accounts we want to update

for (Account a : acc)
{
a.type = 'Suspect - Qualified';
update a;
system.debug(a.type);
}
}
}

 

Thanks!

<->

Hey Guys

 

I am new to Apex coding so please be gentle

 

I need some help

 

Basically i have a huge backlog in my pipeline report, i thought of a way that i can overcome this but i am not sure its its viable

 

What i want to achieve is that is if the opportunity stage are any of the following

Qualified
Proposal
Application Docs Out
Application docs in (Complete)
Sent to Risk
Approved by Risk

 

and there has been no activity ( last modified date in the last 6months from todays date) then change the stage to "Opportunity lost"

 

Is this easily achievable ?

If any one can supply some basic coding for one /two of the stages above it would be truly appreciated

 

Many thanks

  • February 01, 2013
  • Like
  • 0

Hi all, 

 

am new to Sfdc / apex - so forgive the naivety - I've scoured the boards and other material but cant see how/whether the following can be done.

 

Can a trigger be added to an object (Bookings) to create a record in another object (Expense) as a "after insert" trigger
where there is also a "before insert" trigger active ?

 

I have 3 custom objects:

 

Bookings - the capture of a hotel reservation details with a related contact record, payments etc. etc.
Expense - to capture the associated costs of all bookings
Materials - a reference table of materials used for the hotel

 

The first trigger is an "after insert" trigger on Bookings that needs to create a corresponding record in Expense object

 

The second trigger is a "before insert" trigger that does 2 things:

1. takes output of a numeric formula field: Expense.total_nights__c (for example here lets call this "p")

2. Applies (p) * each record type in Materials where Materials.Service__c = Booking

 

Firstly is this possible?, secondly, forgive my naivety but is there any reference code available that does this (or something similar)  or would anyone be brave enought to suggest what this needs to look like?

 

I've had a go and am continually trying but stumblingn in the dark so thought it a good idea to post for help here

 

thanks!

Greetings to everyone!

Here is a question. My APEX controller:

 

public class Fullfunctionality_2 {
 
   private List<Item__c> items;
   private String sortDirection = 'ASC';
   private String sortExp = 'name';
   private String searchStr = ' order by ';
   public Date searchDateCopy;
   public String searchTextCopy;
   public Boolean EndSearch { get; set; }
   public Boolean DelCopy { get; set; }
   public Boolean MakeCopy { get; set; }
   public String NewItemName {get; set;}
   public Integer NewItemQuantity { get; set; }
   public Integer NewItemPrice { get; set; }
   public String NewItemType { get; set; }
   public Date NewItemReleaseDate { get; set; }
   public String IdToDel { get; set; }
   public String searchText {get;set;}
   public Date searchDate { get; set; }
   public List<Item__c> searchResults {get;set;}
   
   public fullfunctionality_2() {

       ViewData();
   }

   public List<SelectOption> getTypes(){
       List<SelectOption> types = new List<SelectOption>();
       Schema.DescribeFieldResult fieldResult = Item__c.Item_Type__c.getDescribe();
       List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
       for( Schema.PicklistEntry f : ple)
           {
              types.add(new SelectOption(f.getLabel(), f.getValue()));
           }       
       return types;
    }
    
   public PageReference add(){

        Item__c NewItem = new Item__c(            
                Name = NewItemName,
                Item_Price__c = NewItemPrice,
                Items_Available__c = NewItemQuantity,
                Item_Type__c = NewItemType,
                Release_Date__c = NewItemReleaseDate
                );
                insert NewItem; 
                ViewData();
                PageReference curPage = ApexPages.currentPage(); 
                curPage.getParameters().put('success','true');
                curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
                curPage.setRedirect(true);
                NewItemName=null;
                NewItemQuantity=null;
                NewItemPrice = null;
                NewItemReleaseDate = null;
                return null; 
    }     
   public PageReference del() {

        Item__c ItemToDel = [SELECT id
                             FROM Item__c
                             WHERE id = :IdToDel];
        delete ItemToDel;   
               
        PageReference curPage = ApexPages.currentPage(); 
        curPage.getParameters().put('success','true');
        curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
        ViewData();     
        return curPage;          
    }    

   public String sortExpression
   {
     get
     {
        return sortExp;
     }
     set
     {
       if (value == sortExp)
         sortDirection = (sortDirection == 'ASC')? 'DESC' : 'ASC';
       else
         sortDirection = 'ASC';
       sortExp = value;
     }
   }

 public String getSortDirection()
 {
    if (sortExpression == null || sortExpression == '')
      return 'ASC';
    else
     return sortDirection;
 }

 public void setSortDirection(String value)
 {  
   sortDirection = value;
 }
  
   public List<Item__c> getItems() {
       return items;
   }

   public PageReference ViewData() {
       if (DelCopy == true){
           searchDateCopy = null;
           searchTextCopy = null;}

       if (MakeCopy == true) {
           searchDateCopy = searchDate;
           searchTextCopy = searchText;
       }    
       string sortFullExp = sortExpression  + ' ' + sortDirection;
       if(searchTextCopy != null) {
           searchstr = 'WHERE Name LIKE \'%' + searchTextCopy + '%\' order by ';}
       if(searchDateCopy != null) {
           searchstr = 'WHERE Name LIKE \'%' + searchTextCopy + '%\' and DAY_ONLY(CreatedDate) =:searchdatecopy order by ';}   
           
       items = Database.query('Select id, Name, Item_Price__c, CreatedDate from Item__c ' + searchstr + sortFullExp);
       

           searchText = null;
           searchDate = null;

       return null;
   }
}

 And here is a test class for controller:

 

@isTest
private class TestFullFunctionality_2 {

String NewItemName = 'NEWITEM';
Integer NewItemPrice = 100;
String NewItemType = 'Solid';
Integer NewItemQuantity = 10;

static testMethod void testAdd() {
TestFullFunctionality_2 ext;       
Item__c NewItem = new Item__c(name = 'NEWITEM', Item_Price__c = 100, Item_Type__c = 'Solid', Items_Available__c = 10 );
insert NewItem;
FullFunctionality_2 Con=new FullFunctionality_2();
Con.add();
Con.del();
Con.viewData();

}
}

 I still cannot understand - why do i get an error:

 

System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Item_Price__c]: [Item_Price__c]

 Maybe someone can help me?

 

Thanks in advance.

I would like to give the users several dropdown input field to build a custom quote, attach those custom fields to values in a template, automatically generate a PDF and then send that PDF to client.

 

I have seen examples of generating a PDF for a quote, but not examples of using custom input fields to build the quote?

 

Do examples for this exist?

 

What aspects of visualforce, apex, etc should I specifically look at to accomplish this?

 

Should the values for these dropdown boxes be stored inline inside the page? Or can/should I create a custom table to store these values so they can be easily accessed and changed/updated when needed?

 

I apologize for the broad general question, but appreciate any help!

 

Kind Regards,

Jim

  • November 22, 2012
  • Like
  • 0

Hello,

 

Are there any APIs that salesforce provide to get list of Companies, Accounts and Contacts that we can use in customController in APEX code.

 

I am a newbie to salesforce development, so please provide the detail or any link about SalesforceAPIs.

 

Thanks.

Just a quick question:

 

I'm playing with Web-to-lead functionality and was hoping to fill in a custom field on our leads using the hidden input tag. One of our custom Lead fields is a lookup/reference field that links to an account and I'd like to fill that in automatically, so that inbound leads are linked to the right generating account.

 

I've tried using the id of an account and also the name of an account to test it, but neither seems to populate. Does anybody know if it's simply not possible? Or should I be using the 18, rather than 15 digit id, etc?

 

With thanks,

Andy

Hi I am fairly new to salesforce so I apologize if this is an obvious question.

 

I am working on a Quote tool. There is both a Quote and Quote Request object. I need to have some of the info from the Quote Request show up as the default text in the quote, the quantity for example. I would do a formula but it doesn't show up when creating a new quote and its read only.

 

I have a master detail setup between the quote and quote request. I tried using the syntax from the formula field type, but it told me it was spelled wrong or didn't exist.

 

Thanks in advanced

 

Tyler

Hi,

 

We are getting the error below in a visualforce page because we have exceeded the API limit.

How can we use/visualize the page again? Should we contact salesforce support?

 

 

Uncaught {faultcode:’sf:REQUEST_LIMIT_EXCEEDED’, faultstring:’REQUEST_LIMIT_EXCEEDED: TotalRequests Limit exceeded.’, detail:{UnexpectedErrorFault:{exceptionCode:’REQUEST_LIMIT_EXCEEDED’, exceptionMessage:’TotalRequests Limit exceeded.’, }, }, }

 

 

Many Thanks,

Altran

 

 

 

  • November 20, 2012
  • Like
  • 0

How to retrieve the account fields from the query [SELECT Accoun.Id,Account.Name FROM Contact Limit 5] in a class.

The code is shown below...

public class Retrieving_Fields {
public List<Contact> con{set;get;}
public void RetrievingFields(){
con=[SELECT Account.Id,Account.Name,Account.Phone FROM Contact LIMIT 5];
System.debug(con);
}
}

please hlelp me out how to retrieve those fields from the above class

Hi,

 

Anyone come across this issue?

I have installed versions 3.5 and 3.6 of Eclipse, and have successfully added the Force.com IDE plugin on both, not having to set any proxy settings as I am not sitting behind one. However when I try to start a new project, and entering my developer login details, I get the Unable to fetch organization details with a Connection timed out: connect error. I have tried this on another machine and all works ok, I am hoping this is a JRE issue, however I have jre 1.6_31 installed. Anyone any ideas or come across this issue before? I havent amended any environment variables should i be?

 

Any help advice is much appreciated.

 

Andrew

Hi,

Can any one help me with the below code, even null values also prepopulating,  I dont want populate null values

 

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/25.0/apex.js")}
var recordTypeName = '{!Account.RecordType}';
var BPRecordId = '';
var theDate = new Date();
var currentYear = theDate.getFullYear();
var NextYear =Number(theDate.getFullYear())+1;

if ( '{!User.Profile}' == 'System Administrator' ){
 if(recordTypeName == 'Channel'){
  var result = sforce.connection.query("Select r.Id From RecordType r where r.SobjectType = 'Business_Plan__c' and r.DeveloperName = 'Distributor' limit 1");
  BPRecordId = result.getArray("records")[0].Id;
 } else if(recordTypeName == 'Grower' || recordTypeName == 'Lawn and Garden'){
  var result = sforce.connection.query("Select r.Id From RecordType r where r.SobjectType = 'Business_Plan__c' and r.DeveloperName = 'Grower' limit 1");
  BPRecordId = result.getArray("records")[0].Id;
 } else if(recordTypeName == 'Influencer'){
  var result = sforce.connection.query("Select r.Id From RecordType r where r.SobjectType = 'Business_Plan__c' and r.DeveloperName = 'Influencer' limit 1");
  BPRecordId = result.getArray("records")[0].Id;
 } else{
  alert('Invalid Operation. Please contact System Admin for details!!');
 }
}

var result =sforce.connection.query("Select Id, Name, Strengths__c, Threats__c, Weakness__c,Opportunities__c From Business_Plan__c where Name = \'" + currentYear + "\' and Account__c = \'{!Account.Id}\' limit 1" );
records = result.getArray("records");
if(records.length > 0 ){
Strength = records[0].Strengths__c;
Opportunity = records[0].Opportunities__c;
Threat = records[0].Threats__c;
Weakness = records[0].Weakness__c;
}

var BPDescription = sforce.connection.describeSObject("Business_Plan__c");
var BPUrlForNew = BPDescription.urlNew.split('com')[1];
var CFID = 'CF'+'00NN0000000KvoM'; // this ID is differnect with the production,please chage it after deployment
var AccountName = '{!Account.Name}';
var aid='{!Account.Id}';
result = sforce.connection.query("Select Id, Name From Business_Plan__c where Name = \'" + NextYear + "\' and Account__c = \'{!Account.Id}\' limit 1" );
records = result.getArray("records");
if(records.length > 0){
var prevId = records[0].Id;
window.top.location=prevId;
}
else{
window.top.location=BPUrlForNew+'?'+CFID+'='+AccountName+'&'+CFID+'_lkid='+aid+'&RecordType='+BPRecordId+'&00NN0000000Kvsi='+Strength+'&00NN0000000KvsV='+Opportunity+'&00NN0000000Kvsl='+Threat+'&00NN0000000Kvsm='+Weakness+'&Name='+NextYear;
}

  • November 12, 2012
  • Like
  • 0

Hello Everyone,

 

      I'm trying to do something with a custom button, but I'm a little lost in how I should go about doing this. I have two custom buttons in my quote object, the first is "Submit\Revise", the second is called "Baan". There is also a custom field that this process is going to be using, its called status. When a new quote is created, the status will be set to new. By default the Baan Button should be somehow locked out/disabled. Once the user completes the quote they can press the "Submit\Revise" button, this will change the status to "Submitted" And will enable the Baan Button.

 

Does anyone have any suggestions for doing this ?

 

Thank You,

Greg Coley

Hi

 

 I am trying to do a self join in contact object to get employee and manager id.

This is the query I tried with no-luck :

 

SELECT p.id,p.Employee_ID__c,p.FirstName,p.LastName,(select c.Employee_ID__c FROM Contact c where c.ReportsToId=p.id) from contact p

 

Could some one let me know what I am doing wrong here.

 

Thanks

Hi all,

 

We use the following code behind a custom button that's displayed on our opp detail page to automatically create a case.  We're using Professional Edition, so we don't have Apex available to us for this to happen automatically when the opp stage is changed to closed won.

 

You can see below that we're using an IF statement to only create the case if the opp stage is closed won, and to alert the user if otherwise.

 

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
var status = "{!Opportunity.StageName}";
var newRecords = [];

if (status == "Closed Won")
{
   var c = new sforce.SObject("Case");
   c.AccountId = "{!Opportunity.AccountId}";
   c.Type = "{!Opportunity.Type}";
   c.Subject = "{!Opportunity.Name}";
   c.Origin = "Converted Opportunity";
   c.Description = "{!Opportunity.Requirement__c}";
   c.ContactId = "{!Opportunity.Opportunity_ContactId__c}";

   newRecords.push(c);

   result = sforce.connection.create(newRecords);
   alert ('Case has been created.');
}
else
{
alert ('Opportunity must be won before a case can be created.');
}

 

I need to complicate this further with another IF statement, but not sure how to do so ... here's what we need:

 

We still need the case only to be created if the opp stage = closed won, and to alert the user if otherwise.

 

We have 6 opp types (we'll call them types 1 to 6), and in addition to the above IF statement, we also need the button to create the case if opp type = 1, 2, 3 or 4, but to alert 'A case cannot be created for opportunity types 5 or 6.' (and not create the case) if the opp type = 5 or 6.

 

Can anyone help me with a tweak to my button code to achieve this?

 

Thanks in advance.

 

Steve

Is there a way to create an APEX case Trigger that will automatically assign case team members based on the user who created the case and/or based on a user in a relative lookup field?

 

If so, would anybody be able to offer me some sample code that could help me jump start my trigger attempt?

  • September 16, 2011
  • Like
  • 0