• apex sfdev
  • NEWBIE
  • 90 Points
  • Member since 2016

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 15
    Likes Given
  • 3
    Questions
  • 12
    Replies
Hi,

  Have written below SOQL to display all product name now i need to add filter to products only start with T has to be retrived. Please suggest me how to add this condition 
 
SELECT Name, Product2.name, Number_of_Nodes__c,UnitPrice,ListPrice,TotalPrice FROM OpportunityLineItem WHERE OpportunityId = '0063400000yU7br'

Tried adding 
Product2.name = 'T%'  but this did not work and not displaying any products

Thanks
Sudhir
Hi,

I am trying to implememnt a standardsetcontroller. I copy pasted the apex code from saslesforce document example-
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_pages_standardsetcontroller.htm
Below is the code-
public class opportunityList2Con {
    // ApexPages.StandardSetController must be instantiated
    // for standard list controllers
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                    [SELECT Name, CloseDate FROM Opportunity]));
            }
            return setCon;
        }
        set;
    }

    // Initialize setCon and return a list of records
    public List<Opportunity> getOpportunities() {
        return (List<Opportunity>) setCon.getRecords();
    }
}

when I save this I get an error-
Error: Compile Error: Incompatible types since an instance of List<SObject> is never an instance of List<Opportunity> at line 17
column 16


Is something changed or if I am missing something?
 
I heard about SLDS, Lightning for visualforce and for apps what is the easiest way to learn lightning in salesforce.

I am in confusion to identify the role of triggers in MVC pattern, some one is saying that triggers operates with database and it comes under model part and some one saying that triggers controlls the data to be inserted or updated to the database and comes to controller part of MVC. Please tell me the role of triggers in MVC pattern.

Thanks.
I am going through TRAILHEAD -  Apex Basics & Database Getting Started with Apex module, there i found, the following,

Apex supports the following data types.
  • A primitive, such as an Integer, Double, Long, Date, Datetime, String, ID, Boolean, among others.
  • An sObject, either as a generic sObject or as a specific sObject, such as an Account, Contact, or MyCustomObject__c (you’ll learn more about sObjects in a later unit.)
  • A collection, including:
  • A list (or array) of primitives, sObjects, user defined objects, objects created from Apexclasses, or collections
  • A set of primitives
  • A map from a primitive to a primitive, sObject, or collection
  • A typed list of values, also known as an enum
  • User-defined Apex classes
  • System-supplied Apex classes

Do we get an apex class for each standard object, please tell me.
Hi,

I have a scenario,that in account object there are two fields 1>status:checkbox
                                                                                       2>status range:process,final
i have wrote a trigger on on account object that when i checked the checkboxthe status range field shoud be complete otherwise incomplete. but if i try to update account records thetriggers are firing everytime. iwant to avoid it.how?
 
I want to use Bootstrap in Visuvalforcepage to desing the ecommerce page, I tried with below code.it shows the tabs in vertical.
Please any one can help me out.
<apex:page docType="html-5.0" showHeader="false" sidebar="false" cache="false" standardStylesheets="false" Controller="Shcontroller">
  <head>
  <title>Bootstrap Case</title>
  <meta charset="utf-8"/>
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">

<!-------->
<div id="content">
    <ul id="tabs" class="nav nav-tabs" data-tabs="tabs">
        <li class="active"><a href="#red" data-toggle="tab">Red</a></li>
        <li><a href="#orange" data-toggle="tab">Orange</a></li>
        <li><a href="#yellow" data-toggle="tab">Yellow</a></li>
        <li><a href="#green" data-toggle="tab">Green</a></li>
        <li><a href="#blue" data-toggle="tab">Blue</a></li>
    </ul>
    <div id="my-tab-content" class="tab-content">
        <div class="tab-pane active" id="red">
            <h1>Red</h1>
            <p>red red red red red red</p>
        </div>
        <div class="tab-pane" id="orange">
            <h1>Orange</h1>
            <p>orange orange orange orange orange</p>
        </div>
        <div class="tab-pane" id="yellow">
            <h1>Yellow</h1>
            <p>yellow yellow yellow yellow yellow</p>
        </div>
        <div class="tab-pane" id="green">
            <h1>Green</h1>
            <p>green green green green green</p>
        </div>
        <div class="tab-pane" id="blue">
            <h1>Blue</h1>
            <p>blue blue blue blue blue</p>
        </div>
    </div>
</div>


<script type="text/javascript">
    jQuery(document).ready(function ($) {
        $('#tabs').tab();
    });
</script>    
</div> <!-- container -->


<script type="text/javascript" src="../bootstrap/js/bootstrap.js"></script>

</body>
</apex:page>
 
i am getting  "Too many SOQL queries: 101" issue when trying ot save a quote and only when the quote lineitems count exceeds 80.
Here is piece of code that apparently is causing issue .
cQuoteGroups = new List<SelectOption>();
            cQuoteGroups.add(new SelectOption('','--None--'));
                  lstQLG = [SELECT Id,Name FROM Quote_Line_Group__c WHERE Quote__c = :cQuote.Id Order By Order__c ASC];
            for(Quote_Line_Group__c qlg : lstQLG){
                if(qlg.Name != 'Change' && qlg.Name != 'Remove'){
                    cQuoteGroups.add(new SelectOption(qlg.Name,qlg.Name));
                                 }
            }
please advise..
how to call apex class from process builder?
I have verified and linked my Trailhead profile's mail ID but the badges are not showing.
Hi,

  Have written below SOQL to display all product name now i need to add filter to products only start with T has to be retrived. Please suggest me how to add this condition 
 
SELECT Name, Product2.name, Number_of_Nodes__c,UnitPrice,ListPrice,TotalPrice FROM OpportunityLineItem WHERE OpportunityId = '0063400000yU7br'

Tried adding 
Product2.name = 'T%'  but this did not work and not displaying any products

Thanks
Sudhir
Hello,

I'm using a developer edition and I don't find Workflow and Approvals in my setup. I just see Workflow and under it "Flows" , "Tasks" , "Email Alerts".
Could you please help me find it.
Here is my code.

//Controller
public with sharing class deleteEvents implements Schedulable
{
    
      public void execute(SchedulableContext SC) 
       {
           
            
            List<Login__c> query=[SELECT Id, Name FROM Login__c WHERE CreatedDate != LAST_N_DAYS:10 and CreatedDate < today ];
            
        List<Login__c> con= query;
        
        if(con!=null)
        {
            delete con;
            }
        }
}

//testclass
@isTest
private class deleteeventsTest{
static List<Login__c> logins = new List<Login__c>();

static testmethod void Test(){
Test.StartTest();


//insert test data
Login__c log=new Login__c();
//fill all mandatory fields needed
log.Name ='testing';
log.Email__c='test@gmail.com';
insert log;

deleteEvents deleve=new deleteEvents();
deleve.execute();
String schedule = '0 15 12 15 1-12 ? *';
List<Login__c> objectList = new List<Login__c>(); 
Test.stopTest();
}
}

I am getting Error: Compile Error: Method does not exist or incorrect signature: [deleteEvents].execute() at line 17 column 1
Please help as how to solve it?
Hi,

I am trying to implememnt a standardsetcontroller. I copy pasted the apex code from saslesforce document example-
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_pages_standardsetcontroller.htm
Below is the code-
public class opportunityList2Con {
    // ApexPages.StandardSetController must be instantiated
    // for standard list controllers
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                    [SELECT Name, CloseDate FROM Opportunity]));
            }
            return setCon;
        }
        set;
    }

    // Initialize setCon and return a list of records
    public List<Opportunity> getOpportunities() {
        return (List<Opportunity>) setCon.getRecords();
    }
}

when I save this I get an error-
Error: Compile Error: Incompatible types since an instance of List<SObject> is never an instance of List<Opportunity> at line 17
column 16


Is something changed or if I am missing something?
 
Am trying to use javascript in a very simple VF page but it is not working can anybody please help me to find out the error.
<----------------PAGE---------------->
<apex:page controller="Example2">

 <script type="text/javascript">
 
    function validate()
    {
        if(document.getElementById('{!$Component.frm.pb.pbs.pbsi1.aa}').value == '')
        {
            alert("FIRST NAME is mandatory");
        }
        if(document.getElementById('{!$Component.frm.pb.pbs.bb}').value == '')
        {
            alert("LAST NAME is mandatory");
        }
         else
        {
            callmove();
            alert("NAME has been inserted CONCATINATED");
        }
    }
        
  </script>  
  <apex:form id="frm"> 
  <apex:actionFunction action="{!move}" name="move" reRender="pb"/>  
   <apex:pageBlock id="pb">   
    <apex:pageBlockSection id="pbs">
               <apex:pageBlockSectionItem ><apex:outputLabel value="FIRST NAME"/></apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem id="pbsi1"><apex:inputText value="{!aa}" id="aa"/></apex:pageBlockSectionItem>
              <apex:pageBlockSectionItem ><apex:outputLabel value="LAST NAME"/></apex:pageBlockSectionItem> 
            <apex:pageBlockSectionItem id="pbsi2"><apex:inputText value="{!bb}" id="bb"/></apex:pageBlockSectionItem>
       <apex:pageBlockSectionItem ><apex:outputLabel value="FULL NAME"/></apex:pageBlockSectionItem> 
            <apex:pageBlockSectionItem id="pbsi3"><apex:inputText value="{!cc}" id="cc"/></apex:pageBlockSectionItem>        
    </apex:pageBlockSection>    
      <apex:pageBlockButtons location="bottom" >      
    <apex:commandButton value="CONCAT" action="{!move}" onclick="move();"/>
        </apex:pageBlockButtons>  
   </apex:pageBlock>
     </apex:form>
 </apex:page>

<----------------CLASS---------------->
public class Example2 {

    public PageReference move() {
    cc=aa+bb;
        return null;
    }

public string aa{get;set;}
public string bb{get;set;}
public string cc{get;set;}
 
public pagereference getMove() {
cc=aa+bb;
return null;
        
    }

}
Hi I am trying to populate a custom field on the Account object with the most recent Task Activity Date where the Task Owner = Account Owner. This is the trigger I have so far, I can't figure out how to add the t.ownerid = a.ownerid filter.
 
trigger LastActivityByOwner on task(after insert) {

  map<id,Account> accounts = new map<id,account>();
    
  for(task record:trigger.new) {
      
    if(record.ownerid.getsobjecttype()==user.sobjecttype) {
        
      if(record.ownerid!=null) {
        accounts.put(record.accountid,new account(id=record.accountid,Last_Activity_By_Owner__c=record.ActivityDate));
      }
    }
  }
  update accounts.values();
}

 
I have a question regarding unmanaged packages..
Does the unmanager packages have a version number? Why are the unmanaged packages used for?

 
HI,

In case object i created one formula field. in this formula field i want to display case owner locale based on this soql query 
" select id,localesidkey from user where id in(select ownerid from case) "

Thanks 
SAi
  • May 20, 2016
  • Like
  • 1
Hi,

  I have writted a controller to check if attached is added or not on a custom object if not added it will show a message else submit for approval. 

  I want to redirect to same page where the user clicked the button from with page refresh I added below code but it is not working please suggest me how to modify the code. 
public class  check_spr_coterm
{
Integer count = 0;
String PageID; 
 public check_spr_coterm()
 {
   SPR__c SP;
   //OpportunityLineItem OLI;
     
   
   SP = [select id,Opportunity__c from SPR__c 
          where Id = : ApexPages.currentPage().getParameters().get('id') limit 1];
   
   PageID = ApexPages.currentPage().getParameters().get('id');
   
   List<AggregateResult> OLI = [select count(id) from OpportunityLineItem 
                                where opportunityid = :SP.Opportunity__c and name like '%COTERM%' ];
    
   List<AggregateResult>  ATH = [select count(id) athcnt from  Attachment 
                                 where parentid = :ApexPages.currentPage().getParameters().get('id')];  
   
   count = (Integer)ATH[0].get('athcnt');  
     
 }
 public void pageAction(){
     if(count ==0){
         ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.info,'You cannot submit as this record dont have attachment'));      
     }
     else
     {
        Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
        req.setObjectId(PageID);
        Approval.ProcessResult result = Approval.process(req);
        //ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.info,'Sucessfully submitted for approval'));
        redirectpage();
      }
     
 }
 
 
 public PageReference redirectpage()
 {
   PageReference pageRef = new PageReference(PageID);
   pageRef.setRedirect(true);
   return pageRef;
 }
 
 
}

hi,

how can we see "Audit logs" of more than 6 months?
Hello - I have tried few solutions ( trigger, process builder, lookup helper) based on what I have found online but no luck so far :/, so any help is appreciated. 

We have a custom object to enter  Incidents: c4g_Incident_Report__c
This object has a lookup field "Reporting Staff" that looks up in the "user" object: c4g_Reporting_Staff__c

Looking for a solution that will auto-populate, before insert, the lookup "Reporting Staff" field with the name of the current user creating the entry. 

User-added image
User-added image
Hi

I need to write a test class from below approval process. Can anyone please help me

    public static Approval.ProcessResult removeQuoteFromApproval(Id quoteId) {
      List<ProcessInstance> piList = [Select p.TargetObjectId, p.Status From ProcessInstance p where TargetObjectId = :quoteId];
      Approval.ProcessResult result =  null;
      if(piList.size() > 0 && piList[0].Status == 'Pending') {
        Approval.ProcessWorkitemRequest pwr = new Approval.ProcessWorkitemRequest();
      pwr.setAction('Removed');
      pwr.setComments('Quote submitted with updated discounts');
      pwr.setWorkitemId(quoteId);
      result = Approval.process(pwr);
      
      if(!result.isSuccess()) {
          Database.Error[] errors = result.getErrors();
          for(Database.Error dbe : errors) {
            system.debug(dbe.getMessage());
          }
        }
      }
      
      return result;
    }

Thanks
I wrote a class when record is inserted it is redirected to another page and should display that record as output field.I wrote a test class for first class,but i dont know how to write test class for pagereference and 2nd class.Please help me

class 1(save record)
-----------
public with sharing class saveInputController {
public string positionname{set;get;}
   
   
    public PageReference saveposition() {
    position__c p=new position__c();
     p.name=positionname;
     insert p;
     PageReference posPage = new PageReference('https://c.ap2.visual.force.com/apex/showinput?id=' + p.name);//I didnt covered this in test class .
     posPage.setRedirect(true);
     return posPage;
    }
}
testclass for class one
------------------------------------

@isTest
public class testsaveInputController{

public static testmethod void v1 (){
position__c p= new Position__c(name='maha');
insert p;
position__c p1= new Position__c(name='maha1');
insert p1;
position__c p2= new Position__c(name='maha2');
insert p2;
Test.startTest();
saveInputController sic=new saveInputController ();
PageReference myVfPage =sic.saveposition();
Test.stopTest();
System.assertEquals('maha', myVfPage );
}
}



class2(display as outfield)(I am not knowing how to write testclass for this because of page reference)
--------------------------------------
public with sharing class showinputcontroller {
public List<position__c> p{get;set;}

public showinputcontroller(){
p=[select name from position__c where name like :ApexPages.currentPage().getParameters().get('id') limit 5];
}

}

Thanks,
Mahanandeesh.
  • May 18, 2016
  • Like
  • 1
I'm having trouble assigning vlues to a list on integers defined in an inner class. I'm trying to assign the value 243 to ArrayOfInt.int_x.

public class wsCsmtpNet201406 {

    public class ArrayOfInt {
        public Integer[] int_x;
        private String[] int_x_type_info = new String[]{'int','https://ws.xxxx.net/2014/06',null,'0','-1','false'};
        private String[] apex_schema_type_info = new String[]{'https://ws.xxxx.net/2014/06','true','false'};
        private String[] field_order_type_info = new String[]{'int_x'};
    }
}
Hello developer heroes!

I'm working through the Apex modules on Trailhead and can't seem to get past this one: https://developer.salesforce.com/en/trailhead/force_com_programmatic_beginner/apex_triggers/apex_triggers_bulk.

Hopefully this doesn't read like a 'please complete the course for me' kinda post, but I have written a trigger that I believe meets the criteria but it isn't passing the check, so I wanted to seek the guidance of the experts.

The challenge is to do this:

Create an Apex trigger for Opportunity that adds a task to any opportunity set to 'Closed Won'.

To complete this challenge, you need to add a trigger for Opportunity. The trigger will add a task to any opportunity inserted or updated with the stage of 'Closed Won'. The task's subject must be 'Follow Up Test Task'.The Apex trigger must be called 'ClosedOpportunityTrigger'

- With 'ClosedOpportunityTrigger' active, if an opportunity is inserted or updated with a stage of 'Closed Won', it will have a task created with the subject 'Follow Up Test Task'.
- To associate the task with the opportunity, fill the 'WhatId' field with the opportunity ID.
- This challenge specifically tests 200 records in one operation.


And here is the trigger I have come up with, which compiles OK and stands up to a manual (though admittedly unbulkified) test:
trigger ClosedOpportunityTrigger on Opportunity (after insert, after update) {

    List<Task> taskList = new List<Task>();
    
    for (Opportunity opp : [SELECT Id, StageName FROM Opportunity WHERE StageName = 'Closed Won' AND Id IN :Trigger.new]){
                    
            taskList.add(new Task(Subject = 'Follow Up Test Task',
                                  WhatId = opp.Id));
       
    }

    if(taskList.size()>0){
        
        insert taskList;
        
    }
    
}
I have tried replacing the SOQL with a straightforward 'for (Opportunity opp : Trigger.new)' and having the taskList.add inside an IF that checks for Closed Won - no luck. I also thought about checking to see if the stage was being changed to Closed Won, rather than the trigger firing on every edit, but I don't think this is what the module is asking for.

Where do you think I'm going wrong?

Huge thanks in advance!

Hi ,

 

     I am confused between synchronous and asynchronous can any one explain me from the scratch what are they actually , and when we use the @future annotation . Please Help me  !!!

 

 

Help is highly appreciated.

 

Thanks in Advance. 

  • June 22, 2013
  • Like
  • 2

I want to get the context user of a page for which I am writing a controller because I want the page to appear one way for a certain type of user and another for a different type of user.

 

This is an example of what I had in mind.

 

String showForm = ($User.Role.Name = 'License Control') ;

 

There seems to be something wrong with my syntax, and I am having trouble finding a solution in the documentation. 

 

 

  • March 27, 2009
  • Like
  • 1