• Vinay J
  • NEWBIE
  • 33 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 20
    Replies
I'm using Developer Edition
i need security token to use on eclipse but i didn't find any option in "My settings"
i have three dates 
date1
date2
date3
 
date1 < date 2 < date 3
date 1 < date3 
Dear firends,

I have two objects in lookup relationship.. Auction and Bid where bid is child.... Whenever a Auction's status is changed to Ended, amount field from bid object is copied to Auction object's field amount by a trigger.. Now, I'm writting test class where I'm creating Auction and the child Bid record..

         Auction__c auction = new Auction__c();
                auction.Auction_Status__c = 'Active';
                auction.Bid_Amount__c = 0;
                insert auction;
        
        Bid__c bid = new Bid__c();
                bid.Auction__c = auction.id;
                bid.Bid_Amount__c = 10;
                insert bid;
        
        auction.Auction_Status__c = 'Ended';
        update auction;
        
        system.debug('*****Auction = ' + auction);
        system.debug('*****Bid = ' + Bid);

The trigger work fine when I test from UI i.e. when I update Auction's status to Ended, Amount from bid is copied to amount on Auction. But in by test class, The debug still gives me amount as 0.

Can someone please help me in understanding why? Debug in trigger also shows the correct amount.
Auction and Bid are objects in lookup where bid is child. For a given auction, I want to find out record id of Bid record with maximum bid amount. Can it be done with aggregate functions? I'm getting correct result when I execute the below mentioned query, but I'm unable to get the record id of bid record.

Select max(Bid_Amount__c) from Bid__c where auction__c='a0617000000MQzm'
I have a text field which saves query like:-

SELECT Id FROM Object WHERE fieldA = TRUE and fieldB = null

Now, based on some other fields on which user provides input, I need to parse the query, remove some of the fields from where clause and add some other.. Can someone please help me in breaking down the query saved in a text field to smaller parts. The keywords 'Where', 'and' and 'Limit' will always be there in the query.

Here's my workflow rule: once the Opportunity stage is moved to "Closed Won" the associated Account type field is updated to "Customer". Is it possible to get the Contact owner and one other Contact field that are associated to that Account to also update alongside the initial Opportunity workflow?

Hi,

I have wrote a trigger that sets a field call "Last Survey Sent" on the Account equal to the "Last Survey Sent" field on the Case. The field on the Case gets set via workflow when a survey is sent to a customer. As I am testing the apex class, I am getting the error: "System.AssertException: Assertion Failed: Expected: null, Actual: 2014-10-10 00:00:00
Class.UpdateSurvey.testLastSurveySent: line 21, column 1". Any ideas on how to resolve this issue?

Trigger:
Trigger UpdateLastSurveySent on Case (after insert, after update) {
    List<Account> accList = new List<Account>();
    for (Case c : Trigger.new) {
        Account acc = new Account(
            Id = c.Account.Id,
            Last_Survey_Sent__c = c.Last_Survey_Sent__c
        );
        accList.add(acc);
    }
    try {
        update accList;
    } catch (Exception ex) {
        System.debug('Could not update Last Survey Sent field on Account with cause: ' + ex.getCause());
    }


Apex Class:
@IsTest   
public class UpdateSurvey {
    @isTest static void testLastSurveySent() {
   
        // Insert Account and Case for tests
        // These may need additional fields, depending on your organization
        Account acc = new Account(
           Name = 'Test Account',
           Website = 'www.test.com',
           Phone = '8888888888'
        );
        insert acc;
        Case c = new Case(
            AccountId = acc.Id,
            Last_Survey_Sent__c = Date.Today()
        );
        insert c;
       
        // Test that the Last Survey Sent field on the account was updated on Insert
        Account accTest = [SELECT Id, Last_Survey_Sent__c FROM Account WHERE Id = :acc.id];
        System.assertEquals(accTest.Last_Survey_Sent__c, Date.Today());
       
        // Test that the Last Survey Sent field on the account changes on Update
        c.Last_Survey_Sent__c = Date.Today()+1;
        update c;
        accTest = [SELECT Id, Last_Survey_Sent__c FROM Account WHERE Id = :acc.id];
        System.assertEquals(accTest.Last_Survey_Sent__c, Date.Today());
    }
}

I think I have done all I can to "bulkify" this trigger but if I update 200 opportunities at once then I get the error about too many SOQL queries. I can't see anything more I need to do for this trigger. What else is there to do?

trigger Update_Sam_Marketing_Customer_Field on Opportunity (after insert, after update, after delete) {

try{
    //the trigger will update the account's SAM Marketing Customer field
    if (! trigger.isDelete) {
    
  List<Id> oppIds = new List<Id>() ;
  List<Id> AccountIds = new List<Id>() ;
  List<Account> AcctToUpdate = new List<Account>() ;
     
      for (opportunity op : trigger.New){
        oppIds.add(op.Id);
        AccountIds.add(op.AccountId);
        
  Map<Id,Opportunity> oppMap = new Map<Id,Opportunity>([Select id, StageName from Opportunity where id in :oppIds and
   name = 'Security Audit Manager'and Status__c != 'Inactive']) ;   
    
  Map<Id,Account> acctMap = new Map<Id,Account>([select id, SAM_Marketing_Customer__c, name, Closed_Won_Opps__c, Type 
   from Account where id in :AccountIDs]);
  
        //Find the account for this opportunity which is being updated
        Account oAccount =  acctMap.get(op.AccountId);
        Opportunity SamOpportunity = oppMap.get(op.Id);

         if (oppMap.isEmpty()){  //No SAM opportunities
    if (oAccount.Closed_Won_Opps__c == 0 && SamOpportunity.StageName != 'Closed Won') {
     oAccount.SAM_Marketing_Customer__c = 5;
    }
    else {
     oAccount.SAM_Marketing_Customer__c = 4;
    }
    AcctToUpdate.add(oAccount);
         }
         else { //There are SAM opportunities so see how many of them are closed/won
          Integer iCountClosedWon = 0;
          
      for(Opportunity samMap: oppMap.values()){       
     if (samMap.StageName == 'Closed Won') {
      iCountClosedWon += 1;
     }      
      }   
          
          if (iCountClosedWon > 0) {
     oAccount.SAM_Marketing_Customer__c = 1;
          }
          else {
           if (oAccount.Closed_Won_Opps__c == 0){
            oAccount.SAM_Marketing_Customer__c = 3;
      //update oAccount;  
           }
           else {
             oAccount.SAM_Marketing_Customer__c = 2;
           }
           
          }
          AcctToUpdate.add(oAccount);
         }
       }
       update AcctToUpdate;
   }
 
 if (trigger.isDelete) {
    
  List<Id> oppIds = new List<Id>() ;
  List<Id> AccountIds = new List<Id>() ;
  List<Account> AcctToUpdate = new List<Account>() ;
    
     for (opportunity op : trigger.Old){
        oppIds.add(op.Id);
        AccountIds.add(op.AccountId);
        
  Map<Id,Opportunity> oppMap = new Map<Id,Opportunity>([Select id, StageName from Opportunity where id in :oppIds and
   name = 'Security Audit Manager'and Status__c != 'Inactive']) ;   
    
  Map<Id,Account> acctMap = new Map<Id,Account>([select id, SAM_Marketing_Customer__c, name, Closed_Won_Opps__c, Type 
   from Account where id in :AccountIDs]);
  
        //Find the account for this opportunity which is being updated
        Account oAccount =  acctMap.get(op.AccountId);
        Opportunity SamOpportunity = oppMap.get(op.Id);

         if (oppMap.isEmpty()){  //No SAM opportunities
    if (oAccount.Closed_Won_Opps__c == 0 && SamOpportunity.StageName != 'Closed Won') {
     oAccount.SAM_Marketing_Customer__c = 5;
    }
    else {
     oAccount.SAM_Marketing_Customer__c = 4;
    }
    AcctToUpdate.add(oAccount);
         }
         else { //There are SAM opportunities so see how many of them are closed/won
          Integer iCountClosedWon = 0;
          
      for(Opportunity samMap: oppMap.values()){       
     if (samMap.StageName == 'Closed Won') {
      iCountClosedWon += 1;
     }      
      }   
          
          if (iCountClosedWon > 0) {
     oAccount.SAM_Marketing_Customer__c = 1;
          }
          else {
           if (oAccount.Closed_Won_Opps__c == 0){
            oAccount.SAM_Marketing_Customer__c = 3;
      //update oAccount;  
           }
           else {
             oAccount.SAM_Marketing_Customer__c = 2;
           }
          }
          AcctToUpdate.add(oAccount);
         }
     }
     update AcctToUpdate;    
   }
}
catch (Exception e ){
            System.debug('Create customer field trigger exception ' + e.getMessage());
            
      }
 }


Hi i have a use case that i need to capture data till line break and save it in varibale.
Any help on this please!!!!!!!

For example: My data is like this:

test name
Street
city,state zip,
Country


I need to get test name in to a variable and use it.Line break is only common in my data so no other way...:(

Hello, 

I am new guy programing with apex, I was looking for a way to fill a picklist with objects data. For example:
I have a class called product with price and name, so we will suppose I added some products like juice, milk, etc.
Then I want to create a page with a picklist and fill it with the data I got (product class).
 Is this possible? how can I?
Could any body provide me some information?

Thank you very much,
Greetings.
Dear friends,

I have a map(integer, list) and a picklist on page with these integers (plus some extra values not present as kep in map). When user selects a value, related list should be diplayed in pageblocktable. If there's no list associated, error should be displayed and pageblocktable should not be visible at all. I have written below code which works file till user selects a value not present as key in the map. Also, in real scenario, it is possible that there's no data inobject and hence, map is empty.. in that case, neither the pageblocktable, nor the picklist should be visible. Can someone please help. It's quite urgent. Below is the code..

*********** Page ************

<apex:page controller="test">
<apex:form >

    <apex:pageMessage detail="{!sError}" severity="Warning" rendered="{!sError <> null}" strength="1" title="No Data" id="message"/> 
   
    <apex:outputPanel rendered="{!isDataPresent == true}">
    <apex:pageblock id="table" >
    <apex:pageblocktable value="{!Data}" var="m"  >
       
        <apex:column value="{!m}" headerValue="Text"/>
    </apex:pageblocktable>
    </apex:pageblock>
    </apex:outputPanel>

    <apex:outputLabel value="Payment Year" ></apex:outputLabel> &nbsp; &nbsp;
    <apex:selectlist id="pmname" value="{!selectedNumber }" multiselect="false" size="1" >
        <apex:selectoptions value="{!listYearsForPage }" >
        </apex:selectoptions>
        <apex:actionSupport event="onchange" reRender="table,message"/>
    </apex:selectlist>


</apex:form>
</apex:page>


**************** Controller ****************

public class test {
   
    public List<SelectOption> listYearsForPage {get;set;}
    public string selectedNumber {get;set;}
    public boolean isDataPresent {get;set;}
    public string sError {get;set;}
   
    public test()
    {
        listYearsForPage = new List<SelectOption>();
        listYearsForPage.add(new selectoption('1','1'));
        listYearsForPage.add(new selectoption('2','2'));
        listYearsForPage.add(new selectoption('3','3'));
        listYearsForPage.add(new selectoption('4','4'));
        isDataPresent = true;   
    }
   
    public map<integer, list<string>> perpData()
    {
        map<integer, list<string>> a = new map<integer, list<string>>();
        a.put(1,new List<String>{'a','b','c'});
        a.put(2,new List<String>{'d','e','f'});
        a.put(3,new List<String>{'g','h','i'});
       
        return a;
    }
   
    public list<string> getData()
    {
        sError = null;
        list<string> l = new list<String>();
        if(selectedNumber == null)
            selectedNumber = '1';
        l = perpData().get(Integer.valueOf(selectedNumber));
        if(l != null)
            isDataPresent = true;
        else {
            isDataPresent = false;
            sError = 'No data';
        }   
        return l;
    }
   
}
There are two objects.obj1 and obj2. I am writing trigger on obj1.status is a picklist field on obj1.if status=new in obj1 i can able to select type=prospect in obj2.Here objects are not related.Is it possible with triggers?