• JonathanBaltz
  • NEWBIE
  • 145 Points
  • Member since 2011
  • Sr. Salesforce Developer
  • UpRight Law


Badges

  • Chatter
    Feed
  • 5
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 45
    Replies
trigger ClosedOpportunityTrigger on Opportunity (before insert) 
{    
    list<task> carry = new list<task>();
    for(opportunity opp: trigger.new)
    {
        if(opp.StageName == 'Closed Won')
        {
           task t = new task(whatid=opp.id,Subject = 'Follow Up Test Task');
            carry.add(t); 
        }
   }
     insert carry;
}

Here is my test class

@isTest
public class TestOppTrig 
{
    static testmethod void testFun()
    {
        Opportunity opp = new opportunity();
        opp.Name = 'Bob';
        opp.StageName = 'closed won';
        opp.CloseDate = system.today();
        insert opp;
        task t = new task();
        t.whatid=opp.id;
        t.subject = 'dasfsdfds';
        insert t;
    }
}
Hello: I am new to apex coding, would greatly appreciate some help with the following problem:
In an “after delete” trigger on opportunitylineitem object I have to access the values or stored IDs for two lookup fields -  ‘opportunity” & “product2”. I can access all other field types like quantity, totalprice etc. using trigger.old, but for those lookup fields, I am getting NULLs. Here is my code:

trigger InvoiceLineItemDeletion on OpportunityLineItem (after delete) {

for (OpportunityLineItem o_l : trigger.old) {

      Opportunity parentOpportunity = o_l.Opportunity; \\ “o_l.Opportunity” returns NULL, please specify the correct format        
      Product2 product2Used = o_l.product2; \\ “o_l.product2” returns NULL

      String qty = o_l.quantity \\ “o_l.quantity” returns correct value
      String parentOpp = [select Name from opportunity where Id =: parentOpportunity.id].Name; \\One more question: is this the correct statement using
                                                                                                                                                                          \\ SOQL to access the parent opportunity name?
      String prodUsed = [select Name from Product2 where Id = :Product2Used.id].Name;
     ……
     …..
}     

      
Thanks very much in advance.
On the standard Accounts object we have too many related lists.  Makes the page look too busy.  I want to keep the hover link for some of the standard objects like Account Teams but do not want the related list to be viewed below.  PAGES ARE TOO LONG AND BUSY.  This is not a custom object.  By reviewing info on site looks like I would have to create a VF page to do this?  That seems like a lot of work to keep something from displaying below.

So, I have this apex class and test class, works fine in prod. I created a new sandbox. I wanted to change one thing in the class, it didn't work. I reverted back to the original code...now the original does not work.

 

Here is my class.

 

public class Smartbox_Equipment_CSV_FileUploader 
{
    ApexPages.StandardController stdCtrl; public Smartbox_Equipment_CSV_FileUploader(ApexPages.StandardController std) {stdCtrl=std;} public PageReference quicksave() {update accstoupload ;return null;} public PageReference fileAccess() {return null;}

public Smartbox_Equipment_CSV_FileUploader(){

}

    public string nameFile{get;set;}
    public Blob contentFile{get;set;}
    String[] filelines = new String[]{};
    List<Smartbox__c> accstoupload;
    
    public Pagereference ReadFile()
    {
        nameFile=contentFile.toString();
        filelines = nameFile.split('\n');
        accstoupload = new List<Smartbox__c>();
        for (Integer i=1;i<filelines.size();i++)
        {
            String[] inputvalues = new String[]{};
            inputvalues = filelines[i].split(',');
            
            Smartbox__c a = new Smartbox__c();
            a.Chassis_Serial__c = inputvalues[0];
            a.Serial_Number__c = inputvalues[2];
            a.CAID__c = inputvalues[3];
            a.SmartCard__c = inputvalues[4];
            a.Opportunity__c = ApexPages.currentPage().getParameters().get('oppId');
            
            accstoupload.add(a);         
        }
        try{
              insert accstoupload;
        }
        catch (Exception e)
        {
            ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template');
            ApexPages.addMessage(errormsg);
        }      
                      
        return null ;}  public List<Smartbox__c> getuploadedEquipment() { if (accstoupload!= NULL) if (accstoupload.size() > 0) return accstoupload; else return null; else return null;

and here is my test class.

@IsTest(SeeAllData=true)
public class Smartbox_Equipment_CSV_FileUploader_Test
{      /* public pageReference fileAccess(){
         Document lstDoc = [select id,name,Body from Document where name = 'test'];
         
         System.Debug('DOC NAME :: '+lstDoc.name);   
         System.Debug('DOCBODY :: '+lstDoc.Body);  
         
         
         return null; 
    }  */     
        public static testMethod void ReadFile() {
    
    Document lstDoc = [select id,name,Body from Document where name = 'eqtest'];
         
        // System.Debug('DOC NAME :: '+lstDoc.name);   
         //System.Debug('DOCBODY :: '+lstDoc.Body);  
       Smartbox_Equipment_CSV_FileUploader  file=new Smartbox_Equipment_CSV_FileUploader ();
       file.fileAccess();
       Blob content= lstDoc.Body;
       file.contentFile = content; //this line doesn't exist yet
       file.ReadFile(); //this line doesn't exist yet

       file.nameFile=content.toString();
       String[] filelines = new String[]{};
       List<Smartbox__c> accstoupload;
       
       accstoupload = new List<Smartbox__c>();
        for (Integer i=1;i<filelines.size();i++)
        {
            String[] inputvalues = new String[]{};
            inputvalues = filelines[i].split(',');
            Smartbox__c a = new Smartbox__c();
            a.Chassis_Serial__c = '12250000';
            a.CAID__c = '10251973';       
            a.Serial_Number__c = '07112006';
            a.SmartCard__c = '07252010';
            a.Status__c = 'Activation Requested';
            
           accstoupload.add(a);         
                   try{
        insert accstoupload;
        }
                catch (Exception e)
        {
            ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template');
            ApexPages.addMessage(errormsg);
        }

    }
        }
        }



Here is the error I get.

Class Smartbox_Equipment_CSV_FileUploader_Test Method Name ReadFile Pass/Fail Fail Error Message System.QueryException: List has no rows for assignment to SObject Stack Trace

Class.Smartbox_Equipment_CSV_FileUploader_Test.ReadFile: line 14, column 1

 

Hi All, 

 

I'm system admin of my organization but getting following error when adding dependencies in change sets : 

 

Insufficient Privileges
You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary. 

 

I've done deployment in recent past but then, just follow simple steps &  I didn't get any issue. Please note, I'm trying to deploy few reports as dependencies along with with few visual force pages ( need for dashboard)

 

Hi all,

I would like to use the SIC Code field, which is a standard field on the Account object.  But when I go to end the layout of the Account, the SIC Code field is not available to be added or removed from the Account object layout.  Is there a setting that I need to change for my user or a setting that I need to set for the Org itself? 

 

Thanks,

Jonathan

trigger ClosedOpportunityTrigger on Opportunity (before insert) 
{    
    list<task> carry = new list<task>();
    for(opportunity opp: trigger.new)
    {
        if(opp.StageName == 'Closed Won')
        {
           task t = new task(whatid=opp.id,Subject = 'Follow Up Test Task');
            carry.add(t); 
        }
   }
     insert carry;
}

Here is my test class

@isTest
public class TestOppTrig 
{
    static testmethod void testFun()
    {
        Opportunity opp = new opportunity();
        opp.Name = 'Bob';
        opp.StageName = 'closed won';
        opp.CloseDate = system.today();
        insert opp;
        task t = new task();
        t.whatid=opp.id;
        t.subject = 'dasfsdfds';
        insert t;
    }
}
what is the Dml operation?
whats is the database.querylocator?
What is the interface?
What is the GovernerLimit in DML?
Hi,
I'm beginner in SalesForce development. I'im trying to connect the Sample Application "SimpleConsole" to my SalesForce account, to try to understand how to connect a .NET app to SalesForce. For this:
  • I've created an application From SalesForce (name is ABITestOAuth)
  • I've got the the Consumer Key and Consumer Secret which I put in my .Net project
  • I've used my Username and password (SalesForce / Force.com devleoper account)
In my code I did the following (like in the sample)
var auth = new AuthenticationClient();
var url = IsSandboxUser.Equals("true", StringComparison.CurrentCultureIgnoreCase)
                ? "https://test.salesforce.com/services/oauth2/token"
                : "https://login.salesforce.com/services/oauth2/token";
 await auth.UsernamePasswordAsync(ConsumerKey, ConsumerSecret, Username, Password, url);

But no way to get a connection.
My question are:
Did I do something wrong until here, or did I miss some important steps?
I wanted to go back to my application in SalesForce to check the Consumer Key and Consumer Secret, but was not able to find this information again. Where can I access to this information after having created the application in SalesForce?

Any help would be welcome
Thanky in advance and best regards
Olivier
Hi Comminity,

I have a requirement where i had to show different fields from 3 different objects into a single pageblock table with checkbox select option. so I am using a wrapper class. My code is below. Can any correct me where I am making the mistake.

public List<AccountTeamWrapper> getAgreementList(){
        if(AgreementList == null){
            agreementList = new List<AccountTeamWrapper>();
           for(Agreement__c agr:[select Id, name, Administrative_Source_System__c from Agreement__c where Customer__c=: accountId]){
                agreementList.add(new AccountTeamWrapper(agr, null));           
           }
List<Agreement_Rep__c> aggRepList = [select Id, Name, Agreement__r.Id, Agreement__r.Name, Agreement__r.Administrative_Source_System__c, REP_AGRMT_BEGIN_DT__c,  REP_AGRMT_END_DT__c
                                                    from Agreement_Rep__c where Agreement__r.Customer__c =: accountId];
            system.debug('************* Agreement size:'+aggRepList.size());
            system.debug('************* Agreement :'+aggRepList);                                                   
            for(Agreement_Rep__c aggRep: aggRepList){
                //aggIds.add(aggRep.Agreement__r.Id);
                agreementList.add(new AccountTeamWrapper(null, aggRep));
            }
return agreementList;
        }
        return null;
    }
public class AccountTeamWrapper{       
        public Agreement__c agreement{get;set;}
        public Agreement_Rep__c agreementRep{get;set;}       
        public Boolean selected{get;set;}       
       
        public AccountTeamWrapper(Agreement__c agr, Agreement_Rep__c aggRep){
            agreement = agr;
            agreementRep = aggRep;
            selected = false;
        }       
    }
}
  • May 16, 2014
  • Like
  • 0
Hello: I am new to apex coding, would greatly appreciate some help with the following problem:
In an “after delete” trigger on opportunitylineitem object I have to access the values or stored IDs for two lookup fields -  ‘opportunity” & “product2”. I can access all other field types like quantity, totalprice etc. using trigger.old, but for those lookup fields, I am getting NULLs. Here is my code:

trigger InvoiceLineItemDeletion on OpportunityLineItem (after delete) {

for (OpportunityLineItem o_l : trigger.old) {

      Opportunity parentOpportunity = o_l.Opportunity; \\ “o_l.Opportunity” returns NULL, please specify the correct format        
      Product2 product2Used = o_l.product2; \\ “o_l.product2” returns NULL

      String qty = o_l.quantity \\ “o_l.quantity” returns correct value
      String parentOpp = [select Name from opportunity where Id =: parentOpportunity.id].Name; \\One more question: is this the correct statement using
                                                                                                                                                                          \\ SOQL to access the parent opportunity name?
      String prodUsed = [select Name from Product2 where Id = :Product2Used.id].Name;
     ……
     …..
}     

      
Thanks very much in advance.
I have a button on Cases called Create Alert.  It creates a record in our custom object Alerts.  I'm trying to get it to update a lookup to itself upon creation but can't seem to get it to update.  I want the Alert Id to be copied into the Master_Alert_Lookup__c field but i'm getting this error when I click save.  If I comment out the update line and look in debug logs, its pulling the correct ID, just not updating the current Alert record.  Can anyone help me with this please?

Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []

public class CW_casetoAlert{
public Alerts__c a{get; set;}


    public CW_casetoAlert(ApexPages.StandardController controller) {
        this.a=(Alerts__c)Controller.getrecord();
    }
   
     public pageReference autorun(){
          ID alertID = ApexPages.CurrentPage().getParameters().get('newid');
          ID caseID =  ApexPages.CurrentPage().getParameters().get('caseID');
        
        
         a.Master_Alert_Lookup__c = alertID;
         //Update the new Alert record
         update a;
         system.debug(a);
              
        //create a new Case Change Association
        Case_Alert_Association__c newCAA = new Case_Alert_Association__c();
         // Fill in the values for the new record
         newCAA.Case__c = caseID;
         newCAA.Alerts__c = alertID;
               
         //Insert the new Case Change Association record
          Database.insert (newCAA);  
       
        PageReference retPage = new PageReference('/' + alertID);
        return retPage;
       }


    }
  • May 16, 2014
  • Like
  • 0
I want to take the contact info under a lead and get it under contacts without losing them as a lead.   For example, John Doe works for ABC Company.  All of John's info is listed under the ABC Co. Lead fields.    There are 2 other people from ABC that are listed under "Contacts"   I want to make sure John Doe is also listed under Contacts without 1) converting and losing ABC as a lead; 2) re-inputting John's info under contacts.  Would like a custom button to do this for all Leads we add in the future as well
On the standard Accounts object we have too many related lists.  Makes the page look too busy.  I want to keep the hover link for some of the standard objects like Account Teams but do not want the related list to be viewed below.  PAGES ARE TOO LONG AND BUSY.  This is not a custom object.  By reviewing info on site looks like I would have to create a VF page to do this?  That seems like a lot of work to keep something from displaying below.
I want to diaplay the description field as readable where I am inserting the description field using an email template. Here description field is displaying in html code. I want to display the html code as readble for task object. Please help me in acheiving this.

Hi,

 

I am trying to add the Notes and Attachments Section on my Visualforce Page and I keep getting the error as below:


'NotesAndAttachments' is not a valid child relationship name for entity Test Object

 

I used   <apex:relatedList subject="{!Test_Object__c}" list="NotesAndAttachments"/>

 

Can someone please suggest or point out my mistake.

 

Thanks!

So I upgraded my force.com IDE according to the instructions here:

http://wiki.developerforce.com/page/Updating_the_Force.com_IDE

 

It looked like it was successful, and the IDE has been restarted.

 

However, when I try to create a new apex class, the only version available in the dropdown is 26.0.  How can I get this so that I can choose later API versions when creating new classes?

 

  • September 18, 2013
  • Like
  • 0

Hi,

 

I have Custom visualforce page which has two inputFields along with a button as Save.I have written some validation rules, which are working fine and it is getting displayed on the top of page. But the thing is though I entered the correct values and click on save button the eror messages are still appearing and not allowing to save the values. Please can someone help me in finding a solution.

 

Thanks,

Arun.

Hello!

 

I am having an error when I try to save my code.  This is stating that the object I am referencing is not accessible.  If anyone has any Ideas please let me know!  this has me stumped!

 

trigger AutoCreateCommissionableUser on pymt__PaymentX__c (after insert) {
List<Commissionable_User__c> CU = new List<Commissionable_User__c>();

for (pymt__PaymentX__c newPayment: Trigger.New) {

if (pymt__PaymentX__c.pymt__Contact__c <> null) {

CU.add(new Commissionable_User__c(

RecordTypeId = [select Id from RecordType where Name = 'Payment' and SobjectType = 'Commissionable_User__c'].Id,

Payment__c =Payment.Id,
Commissionable_User__c =pymt__PaymentX__c.Owner.Id ,
Owner=pymt__PaymentX__c.Owner.Id

));

}

}

insert CU;

}

I have built a custom report using Visual Force. I am trying to give the end user the ability to sort the report by a few different fields. I have created a pick list on a Custom Object that contains the field names (API Names) that the user can sort by. In my class I query the Custom object to get the field the end user wants to sort by, I store that in a variable. I then want to use that vairble to order by my SOQL statement that builds the report.

 

Here is my codes:

 

//Set the variable from the custom field

List<Custom__c> SortBy = [Select SortBy__C from Custom__c Where Name = 'FreightDashboard' ];

 

//My Query to build the report:

SELECT Estimated_Ship_Date__c, Date_Shipped__c, Opportunity.CloseDate, Opportunity.Account.Name, From OpportunityLineItem WHERE Opportunity.StageName = 'Closed Won' and (NOT ShippingType__c like '%Small Parcel%') ORDER BY :SortBY]

 

I want my end user to be able to sort by Estimated_Ship_Date__c or  Date_Shipped__c or Opportunity.CloseDate at their choosing.

 

Any help?

I'm attempting to upload data into my Sandbox instance using the Bulk API. This works with Test Orgs that I've configured and used for some time. However, I just spun up a new Sandbox and I now get this response when attempting to upload data via the Bulk API:

 

{"exceptionCode"=>["FeatureNotEnabled"],
"exceptionMessage"=>["Async API not enabled"],
"xmlns"=>"http://www.force.com/2009/06/asyncapi/dataload"}

 

What do I need to do to enable the Bulk API in my Sandbox? 

So, I have this apex class and test class, works fine in prod. I created a new sandbox. I wanted to change one thing in the class, it didn't work. I reverted back to the original code...now the original does not work.

 

Here is my class.

 

public class Smartbox_Equipment_CSV_FileUploader 
{
    ApexPages.StandardController stdCtrl; public Smartbox_Equipment_CSV_FileUploader(ApexPages.StandardController std) {stdCtrl=std;} public PageReference quicksave() {update accstoupload ;return null;} public PageReference fileAccess() {return null;}

public Smartbox_Equipment_CSV_FileUploader(){

}

    public string nameFile{get;set;}
    public Blob contentFile{get;set;}
    String[] filelines = new String[]{};
    List<Smartbox__c> accstoupload;
    
    public Pagereference ReadFile()
    {
        nameFile=contentFile.toString();
        filelines = nameFile.split('\n');
        accstoupload = new List<Smartbox__c>();
        for (Integer i=1;i<filelines.size();i++)
        {
            String[] inputvalues = new String[]{};
            inputvalues = filelines[i].split(',');
            
            Smartbox__c a = new Smartbox__c();
            a.Chassis_Serial__c = inputvalues[0];
            a.Serial_Number__c = inputvalues[2];
            a.CAID__c = inputvalues[3];
            a.SmartCard__c = inputvalues[4];
            a.Opportunity__c = ApexPages.currentPage().getParameters().get('oppId');
            
            accstoupload.add(a);         
        }
        try{
              insert accstoupload;
        }
        catch (Exception e)
        {
            ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template');
            ApexPages.addMessage(errormsg);
        }      
                      
        return null ;}  public List<Smartbox__c> getuploadedEquipment() { if (accstoupload!= NULL) if (accstoupload.size() > 0) return accstoupload; else return null; else return null;

and here is my test class.

@IsTest(SeeAllData=true)
public class Smartbox_Equipment_CSV_FileUploader_Test
{      /* public pageReference fileAccess(){
         Document lstDoc = [select id,name,Body from Document where name = 'test'];
         
         System.Debug('DOC NAME :: '+lstDoc.name);   
         System.Debug('DOCBODY :: '+lstDoc.Body);  
         
         
         return null; 
    }  */     
        public static testMethod void ReadFile() {
    
    Document lstDoc = [select id,name,Body from Document where name = 'eqtest'];
         
        // System.Debug('DOC NAME :: '+lstDoc.name);   
         //System.Debug('DOCBODY :: '+lstDoc.Body);  
       Smartbox_Equipment_CSV_FileUploader  file=new Smartbox_Equipment_CSV_FileUploader ();
       file.fileAccess();
       Blob content= lstDoc.Body;
       file.contentFile = content; //this line doesn't exist yet
       file.ReadFile(); //this line doesn't exist yet

       file.nameFile=content.toString();
       String[] filelines = new String[]{};
       List<Smartbox__c> accstoupload;
       
       accstoupload = new List<Smartbox__c>();
        for (Integer i=1;i<filelines.size();i++)
        {
            String[] inputvalues = new String[]{};
            inputvalues = filelines[i].split(',');
            Smartbox__c a = new Smartbox__c();
            a.Chassis_Serial__c = '12250000';
            a.CAID__c = '10251973';       
            a.Serial_Number__c = '07112006';
            a.SmartCard__c = '07252010';
            a.Status__c = 'Activation Requested';
            
           accstoupload.add(a);         
                   try{
        insert accstoupload;
        }
                catch (Exception e)
        {
            ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template');
            ApexPages.addMessage(errormsg);
        }

    }
        }
        }



Here is the error I get.

Class Smartbox_Equipment_CSV_FileUploader_Test Method Name ReadFile Pass/Fail Fail Error Message System.QueryException: List has no rows for assignment to SObject Stack Trace

Class.Smartbox_Equipment_CSV_FileUploader_Test.ReadFile: line 14, column 1

 

Hi All,

 

We have a process in our Enterprise edition of Salesforce, where our Sales Team need to create a Lead when an Opportunity is set to 'Closed Lost'.  


The reason for this, is that our Telemarketing team can then 'warm-up' those Leads depending on why the Opportunity was Lost in the first place.

I'm creating a button to do this, but am having difficulty getting the First Name and Last Name of the contact, specified in the Contact Role, pre-popuating in the new Lead.

 

My button code, which I was kindly given by another member of the Salesforce Community, is:

 

 

{!REQUIRESCRIPT('/soap/ajax/28.0/connection.js')} 

var contactRole = sforce.connection.query("SELECT Contact.FirstName, Contact.LastName FROM OpportunityContactRole WHERE OpportunityId='{!Opportunity.Id}' AND IsPrimary = TRUE"); 

var firstName; 
var lastName; 

if (contactRole.size == 1){ 
firstName = contactRole.records.Contact.FirstName; 
lastName = contactRole.records.Contact.LastName; 


location.href = '/00Q/e?lea3={!Opportunity.Account}&name_firstlea2=' + firstName + '&name_lastlea2=' + lastName + '&lea12={!Account.Website}&00N20000002X2tm={!Opportunity.Name}&00N20000003ZQZU={!Opportunity.New_Biz_Sales_person__c}&00N20000003GkTu={!Opportunity.OwnerFullName}&00N20000002X2tr={!Opportunity.Monthly_Value__c}&00N20000003GkTz={!Opportunity.LeadSource}&00N20000003GkU4={!Opportunity.CloseDate}&00N20000002X2tw={!Opportunity.Account}&00N20000002X2u1={!Opportunity.Description}&00N20000003GkUE={!Opportunity.Reason_For_Win_Loss__c}&00N20000003GkU9={!Opportunity.Notes_from_Lead__c}';

 

This only works when there is one Contact in the Opportunity Contact Roles section; if there are more than one Contact in the Contact Roles section, and even if only one of them is selected as Primary, an error message is received.

 

Can anybody assist with how I can amend this code to 'ignore' the other Contacts and just use the Primary Contact for the new Lead?  Please be aware that I am not a developer and, therefore, have limited knowledge of 'code' and what it does.

 

Any assistance would be greatfully received.

 

Thanks

Can the following logic be implemented – For each EXTERNAL_ID, if STATUS field is populated with value ‘T’ AND field ‘TERM_DATE’ does not equal ‘{PREVIOUS DAY’S DATE}’ exclude the record from the daily load.