• Anoop Asok
  • NEWBIE
  • 105 Points
  • Member since 2012

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

can anyone tell me how to get this hierarchy

Parent Id
            ChildID    CountOfPickupDays(formula field)...decimal
            CHildID    CountOfPickupDays
            ChildID    CountOfPickupDays
                      

Example: By name rather than ID

Caffe Nero Group Ltd                  Count Of PickUp days Field(Formmula Field)
                          Caffe Nero   =           2
                          CaffeNero    =          1
                          Starbucks    =           0
                          Caffe Nero Group Ltd = 5
                           Caffe Nero          =    1

i want to get parent Id----->Child IDs-----> All Pickup Days

i have used map for getting parent ID assoiated to its child
Map<Id,List<Id>> servMap = new Map<Id,List<Id>>();

for(Service__c serObj: serviceList){
Id parentAccId = serObj.Customer__r.Grand_Parent_Account__c;
Id AccountId = serObj.Customer__r.id;

if(serObj.Status__c == 'Active'){
if(servMap.get(parentAccId)==null)
{
servMap.put(parentAccId,new list<Id>{AccountId});
}
else
{
servMap.get(parentAccId).add(AccountId);
}
}
got all the child IDs according to parent  

now i want to get count of pickup days according to its child ids

 

Give me some idea

  • September 05, 2012
  • Like
  • 0

Please make me correct for writing unit test class for the following Apex class-

 

public class practiseOneController
 {
    public Account getAccount()
    {
        Account[] acc= [select id,Name,(select id,firstname,lastname from Contacts limit 5) from Account where id=
                 :System.currentPageReference().getParameters().get('id')];
                 
                 if(acc.size()>0)
                 {
                    return acc[0];
                 
                 }
                  else
                  {
                    return null;
                  
                  }
                 
                 
    }
    
    
    // Test Method for this main class
    
     static testMethod void TestpractiseOneController()
     {
       practiseOneController testObj= new practiseOneController();
       
       Account testAcc=new Account();
       testAcc.Name='testaccount';
       insert testAcc;
       testObj.getAccount();
     
     
     
     }
    
    
    

}

 I tried but not getting to cover

 :System.currentPageReference().getParameters().get('id')];
                 
                 if(acc.size()>0)
                 {
                    return acc[0];
                 
                 }

 In this apex class i am trying to show the accociated contacts with the Account.

 

Thanks & regards,

JaanVivek

How to achieve this requirement?

Select the value from picklist and related other picklist and click on button on a vf page then a specific vf page should display.

Hi all i have this trigger where i want to update some values on an opp based on values in the opps line items but im getting the "maximum trigger depth exceeded" error but i dont really know how to resolve it, can anyone see what i can do here?

 

trigger opportunitySubTotalSummaryTrigger2 on Opportunity (after insert, after update)
{
    list<id> OppIds = new list<id>();
    list<Opportunity> oppsWithLineItems = new list<Opportunity>();
    list<Opportunity> oppsToUpdate = new list<Opportunity>();
    
    for(Opportunity o : trigger.new)
    {
        if(o.HasOpportunityLineItem == true)
            OppIds.add(o.id);        
    }
    
    oppsWithLineItems = [Select o.System_Revenue_2__c, System_Margin_2__c, CS_Revenue_2__c, CS_Margin_2__c, PS_Revenue_2__c, PS_Margin_2__c, o.Name, o.Id, (Select Id, OpportunityId, SortOrder, PricebookEntryId, CurrencyIsoCode, Quantity, TotalPrice, UnitPrice, ListPrice, ServiceDate, Description, Unit_Cost_Price__c, Unit_List_Price__c, Vendor_Quote_Reference__c, Vendor_Registration__c, Total_Cost_Price__c, Total_List_Price__c, Total_Sell_Price__c, Total_Product_Margin__c, Margin_percent__c, Test_Type__c, Type__c, CS_Revenue__c, CS_Margin__c, System_Revenue__c, PS_Margin__c, PS_Revenue__c, System_Margin__c, Other_Revenue__c, Other_Margin__c From OpportunityLineItems) From Opportunity o where o.HasOpportunityLineItem = true and id in :oppIds];
    
    for(Opportunity o : oppsWithLineItems)
    {
        for(OpportunityLineItem oli : o.OpportunityLineItems)
        {
            o.System_Revenue_2__c += oli.System_Revenue__c;
        }
    }
    update(oppsWithLineItems);
}

 

Thanks All

Hi everyone,

Is there a lastmodifiedby and lastmodifieddate for list views? If yes, where can we see that?

 

Thanks,

Anoop

Hi,
my goal is to keep only one contact TAB opened in Console all the time , if there is already a tab opened i need to close it and open the new tab.

I have a VF section on standard detail page and i added addEventListener for OPEN_TAB. When the EventListener function executes on TAB open getting the error saying un supported API function. does it means i can't add EventListener on a VF section? if so is there in other work around for this?

function getAllTabIds() {
// get all Tab ID's
sforce.console.getEnclosingPrimaryTabIds(closeAlltabs);
}
var closeAlltabs = function closeAlltabs(results) {
alert('closeAlltabs Called'+result.ids);
var tabId = result.id;
};
sforce.console.addEventListener(sforce.console.ConsoleEvent.OPEN_TAB, getAllTabIds, { tabId : sforce.console.getEnclosingTabId() });
  • September 11, 2015
  • Like
  • 0
Hi all,

I have a Trigger on the Task object. I am trying to perform a get from a Map using an ID from a previoulsy populated List. The list will only every have 1 ID in it, but I still need to tell it which ID to use. Now I could simply use the WhoId, but without going into detail I can't use that for other reasons based on how the trigger will function. 

Based on the code below, is this correct?
-------------------------------------------------------------------------

trigger ContactAccountLastActivity on Task (after insert, after update) {

    List<String> lstWhoIds = new List<String>();

for( Task t : Trigger.new )
    {
        // Add the "Who" from the task to the lstWhoIds List
        lstWhoIds.add(t.WhoId);    
    }
    
        // Query Contact Object to get Contact fields and create
        // a Map of Contact ID to Contact fields using lstContactFields Query results
    List<Contact> lstContactFields = new List<Contact>([SELECT Id, AccountId, Last_Contacted_Date__c, Last_Contacted_By__c
                                                     FROM Contact
                                                     WHERE Id in :lstWhoIds]);
    Map<String, Contact> mapWhoIds = new Map<String, Contact>(lstContactFields);

for( task t : Trigger.new )
    {
            if( (t.type == 'Telephone In' || t.type == 'Telephone Out' || t.type == 'Visit/Meeting') && t.status == 'Completed' )
            {
                if( Date.valueOf(t.Completed_Date__c) >= mapWhoIds.get(lstWhoIds).Last_Contacted_Date__c )
                {
                    mapWhoIds.get(lstWhoIds[0]).Last_Contacted_Date__c = Date.valueOf(t.Completed_Date__c);
                }
        }
}

mapWhoIds.get(lstWhoIds[0]).Last_Contacted_Date__c  does not provide any errors
mapWhoIds.get(lstWhoIds).Last_Contacted_Date__c  give error: "Incompatible key type LIST<String> for MAP<String, Contact>
 
Is there a way to setup email alerts when a field in Tasks change? I dont have the set E-mail Alert option when I try to add a workflow step for the TASKS object

SFDC support person directed me to developers as the only workaround is to use apex trigger which deals with constructing codes to make it work.

Can anyone help me?
I have a class backing a visualforce page for a custom forecasting module. Depending on which user is updating the forecast data, I want to update a different set of fields. In my visualforce I display a list of opportunities, and I want to display all the fields I query for regardless of which user is viewing the forecast, i.e. I can't just not query some fields depending on which user I'm dealing with. It looks something like this:
 
//define user roles
Boolean userIsSalesRep = false;
Boolean userIsManager = false;

if(boo=foo){
    userIsSalesRep = true;
}else{
    userIsManager = true;
}
So I have 2 Booleans that show me who I'm dealing with, then I have a method to update the opportunities. When I do the update, I don't want to update certain fields depending on which user is calling the update.
public List<Opportunity> opportunities {get; set;}
......
......

public void save(){

    // I want to do something like this-->
    if(userIsSalesRep){
        for(Opportunity o: opportunities){
            o.remove('fieldXX');
        }
    }

    update(opportunities);
}
Does anybody have a good idea on how to do this. I have some clunky ideas on what I could do, but I really don't want to make it clunky.


 

I am trying to get the value 'S848270' out of the following text string... 

 

"Tel: 0712222222
Email: xxxxxxx@gmail.com
Your property: BEREA, 8 Tudhope Heights, Corner Primrose & Tudhope
Street (S848270)
Message: Hi Obotseng Phokompe, I found this listing on Private Property
and would like more information."

 

 

I am trying to use the following reg expression.  'S[0-9][0-9][0-9][0-9][0-9][0-9]'

 

When i test it in a 3rd party reg expression tool it finds the value ok. But in my apex code it is not finding a match for some reason? Do i need to try put other characters into the reg expression because i am using apex? I have no idea why its not working if it appears to work in the 3rd party reg expression matching tool.

 

 

Hi everyone,

Is there a lastmodifiedby and lastmodifieddate for list views? If yes, where can we see that?

 

Thanks,

Anoop

Hi, I am trying to develop a trigger which will insert a unique value for a text field for the newly entered record. The value to the text field should be assigned depending on the value of the another Picklist field. The trigger is as follows.

trigger PPCIDtrigger on Lead (before insert, before update)
{    
    if(Trigger.isInsert || Trigger.isUpdate)
    {
        for(Lead a: Trigger.new)
        {
            if (a.Lead_Type__c == 'Paisapak Consumer')
            {
                a.PPC_ID__c='WS' +  ;        
            }
        }
    }
}


Here Lead Type is a pick list and PPC ID is a unique text field. I want to assign a value in PPC ID field only when Lead Type = "Paisapak Consumer". One more thing I want to add after "WS" text in PPC ID field is sequence number which shall start by 001 for the first record whose Lead Type is "Paisapak Consumer" and then shall be increased by 1 for every next new record whose Lead Type is "Paisapak Consumer". Will be grateful if I get assistance for this.

Thanks.

how to count number of records in same object.

I require a way to count no of records in same custom object.

 

 

Can anyone say what is the best way to get it.

 

thanks

  • September 10, 2012
  • Like
  • 0

As a best practice, i know that we need to gracefully recover from exceptions and one way is to handle the transaction is by creating a record in a custom log object.  However, after readung up, i think this will not work on a before insert/update since the transaction is rolled back completely which would prevent the error to be inserted into the object unless it;s an after insert/update.

 

 Is this true? Also if it is, what is a best way to handle exceptions associated with before insert/update triggers?

  • September 10, 2012
  • Like
  • 0

can anyone tell me how to get this hierarchy

Parent Id
            ChildID    CountOfPickupDays(formula field)...decimal
            CHildID    CountOfPickupDays
            ChildID    CountOfPickupDays
                      

Example: By name rather than ID

Caffe Nero Group Ltd                  Count Of PickUp days Field(Formmula Field)
                          Caffe Nero   =           2
                          CaffeNero    =          1
                          Starbucks    =           0
                          Caffe Nero Group Ltd = 5
                           Caffe Nero          =    1

i want to get parent Id----->Child IDs-----> All Pickup Days

i have used map for getting parent ID assoiated to its child
Map<Id,List<Id>> servMap = new Map<Id,List<Id>>();

for(Service__c serObj: serviceList){
Id parentAccId = serObj.Customer__r.Grand_Parent_Account__c;
Id AccountId = serObj.Customer__r.id;

if(serObj.Status__c == 'Active'){
if(servMap.get(parentAccId)==null)
{
servMap.put(parentAccId,new list<Id>{AccountId});
}
else
{
servMap.get(parentAccId).add(AccountId);
}
}
got all the child IDs according to parent  

now i want to get count of pickup days according to its child ids

 

Give me some idea

  • September 05, 2012
  • Like
  • 0

trigger OnAccount_ConfirmToChange on Account (before update) {
      List<Account> accList = [select Id,Name,(select AccountId,Name from Contacts) from account where Id =                   :Trigger.newMap.keySet()];
// Map<Id,Contact> conMap = new Map<Id,Contact>([select Id from Contact where AccountId in: accList.Id]);
     List<Contact> conList = [select Name,isAccountChanged__c from Contact where AccountId in: accList];
     for(Account acc:accList){
         for(Contact con:conList){
             if(conList.size() > 0){
                 if(con.isAccountChanged__c == false){
                 Account ar = Trigger.oldMap.get(acc.Id);
                 ar.addError('Only if the isAccountChanged is checked,You can modify the account!');
                }
           }
       }
    }
}

Hi, as the code abrove. I want to add a error message on updated account when its contact's field isAccountChanged__c  is false.But I get the error "System.FinalException: SObject row does not allow errors" ,could you help me?

  • September 05, 2012
  • Like
  • 0

Please make me correct for writing unit test class for the following Apex class-

 

public class practiseOneController
 {
    public Account getAccount()
    {
        Account[] acc= [select id,Name,(select id,firstname,lastname from Contacts limit 5) from Account where id=
                 :System.currentPageReference().getParameters().get('id')];
                 
                 if(acc.size()>0)
                 {
                    return acc[0];
                 
                 }
                  else
                  {
                    return null;
                  
                  }
                 
                 
    }
    
    
    // Test Method for this main class
    
     static testMethod void TestpractiseOneController()
     {
       practiseOneController testObj= new practiseOneController();
       
       Account testAcc=new Account();
       testAcc.Name='testaccount';
       insert testAcc;
       testObj.getAccount();
     
     
     
     }
    
    
    

}

 I tried but not getting to cover

 :System.currentPageReference().getParameters().get('id')];
                 
                 if(acc.size()>0)
                 {
                    return acc[0];
                 
                 }

 In this apex class i am trying to show the accociated contacts with the Account.

 

Thanks & regards,

JaanVivek

I'm very new to programming and even newer to apex, I've modified the below code from a sample I found but have no idea how to write a test class for it.  If it is not to difficult would anyone have an idea?

 

trigger SumSalesOnAccount on Account (before update)
{

Integer i = 0;

Account acc = Trigger.new[i];

// Current Account ID
String intTest = Trigger.new[i].Id;



//Step 2. Create a list of Transactions who are children of this Account record.
List<Transaction__c> trn = [Select Transaction__c.Id, Transaction__c.Gross_Amount__c, Transaction__c.Month_Rank__c From Transaction__c where Transaction__c.Firm__c =: intTest AND Transaction__c.Month_Rank__c =: '-1'];

Double a = 0;

// Loop through the filtered Transactions and sum up their amounts.
for(Transaction__c tr : trn)
{
If (tr.Gross_Amount__c != Null)
{
a += tr.Gross_Amount__c;
}
}
acc.Sales_1__c = a;

//Step 2.2. Create a list of Transactions who are children of this Account record.
List<Transaction__c> trn2 = [Select Transaction__c.Id, Transaction__c.Gross_Amount__c, Transaction__c.Month_Rank__c From Transaction__c where Transaction__c.Firm__c =: intTest AND Transaction__c.Month_Rank__c =: '-2'];

Double b = 0;

// Loop through the filtered Tranasctions and sum up their amounts.
for(Transaction__c tr2 : trn2)
{
If (tr2.Gross_Amount__c != Null)
{
b += tr2.Gross_Amount__c;
}
}
acc.Sales_2__c = b;

//Step 2.3. Create a list of Transactions who are children of this Account record.
List<Transaction__c> trn3 = [Select Transaction__c.Id, Transaction__c.Gross_Amount__c, Transaction__c.Month_Rank__c From Transaction__c where Transaction__c.Firm__c =: intTest AND Transaction__c.Month_Rank__c =: '-3'];

Double c = 0;

// Loop through the filtered Tranasctions and sum up their amounts.
for(Transaction__c tr3 : trn3)
{
If (tr3.Gross_Amount__c != Null)
{
c += tr3.Gross_Amount__c;
}
}
acc.Sales_3__c = c;

//Step 2.4. Create a list of Transactions who are children of this Account record.
List<Transaction__c> trn4 = [Select Transaction__c.Id, Transaction__c.Gross_Amount__c, Transaction__c.Month_Rank__c From Transaction__c where Transaction__c.Firm__c =: intTest AND Transaction__c.Month_Rank__c =: '-4'];

Double d = 0;

// Loop through the filtered Tranasctions and sum up their amounts.
for(Transaction__c tr4 : trn4)
{
If (tr4.Gross_Amount__c != Null)
{
d += tr4.Gross_Amount__c;
}
}
acc.Sales_4__c = d;

//Step 2.5. Create a list of Transactions who are children of this Account record.
List<Transaction__c> trn5 = [Select Transaction__c.Id, Transaction__c.Gross_Amount__c, Transaction__c.Month_Rank__c From Transaction__c where Transaction__c.Firm__c =: intTest AND Transaction__c.Month_Rank__c =: '-5'];

Double e= 0;

// Loop through the filtered Tranasctions and sum up their amounts.
for(Transaction__c tr5 : trn5)
{
If (tr5.Gross_Amount__c != Null)
{
e += tr5.Gross_Amount__c;
}
}
acc.Sales_5__c = e;

//Step 2.6. Create a list of Transactions who are children of this Account record.
List<Transaction__c> trn6 = [Select Transaction__c.Id, Transaction__c.Gross_Amount__c, Transaction__c.Month_Rank__c From Transaction__c where Transaction__c.Firm__c =: intTest AND Transaction__c.Month_Rank__c =: '-6'];

Double f = 0;

// Loop through the filtered Tranasctions and sum up their amounts.
for(Transaction__c tr6 : trn6)
{
If (tr6.Gross_Amount__c != Null)
{
f += tr6.Gross_Amount__c;
}
}
acc.Sales_6__c = f;
}