• RSK
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 11
    Replies

Hi, I'm trying to update a custom field asset_count__c which counts no of assets of an account, when updating account and getting the following error. Any help must me highly appreciated.

 

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger updateAssetCounton caused an unexpected exception, contact your administrator: updateAssetCounton: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 00190000004K1vLAAS; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 00190000004K1vL) is currently in trigger updateAssetCounton, therefore it cannot recursively update itself: []: Trigger.updateAssetCounton: line 20, column 1

 

trigger updateAssetCounton on Account (before update) {

List<Account> updateAssetCountList = new List<Account>();
List<Asset> assId = new List<Asset>();
Map<Id,Integer> mapAccount = new Map<Id,Integer>();
set<Id> accountIds = new set<Id>();


for(Account acc : Trigger.new){
      accountIds.add(acc.Id);
}
mapAccount = foundAsset(accountIds);

updateAssetCountList = [select asset_count__c,id from Account where Id in : mapAccount.KeySet()];
for(Account a: updateAssetCountList)
{
    a.asset_count__c = mapAccount.get(a.Id);
}

update updateAssetCountList;   // line 20




public Map<Id,Integer> foundAsset( set<Id> AccountIds2){

assId = [select id,AccountId from Asset where AccountId in:accountIds2];

if(assId.size()>0)
{
for(Asset accId : assId)
{
    if(mapAccount.containsKey(

accId.AccountId))
    {
        integer sum;
        sum = mapAccount.get(accId.AccountId);
        sum = sum+1;
        mapAccount.put(accId.AccountId,sum);
    }
    else
    {
        integer sum;
        sum = 1;
        mapAccount.put(accId.AccountId,sum);
    }
 }
}

else
{
    for(Id accId : accountIds2)
   {
       mapAccount.put(accId,0);
   }

}

 return mapAccount;
}

}
Thanks a ton in advance !
RSK

Hi,

I have a trigger on Asset to update no. of  assests of an Account on a account  custom field, it is working as expcted but failing to update assets when  merge accounts.  Any help must be highly appreciated.

 

Here is my trigger:

trigger updateAssetCountonAccount on Asset(after insert,after update,after delete) {
List<Account> updateAssetCountList = new List<Account>();
List<Asset> assId = new List<Asset>();
Map<Id,Integer> mapAccount = new Map<Id,Integer>();
set<Id> accountIds = new set<Id>();
for(Asset a : Trigger.new){
      accountIds.add(a.AccountId);
}

mapAccount = foundAsset(accountIds);
updateAssetCountList = [select asset_count__c,id from Account where Id in : mapAccount.KeySet()];
for(Account a: updateAssetCountList)
{
    a.asset_count__c = mapAccount.get(a.Id);
}

update updateAssetCountList;

public Map<Id,Integer> foundAsset( set<Id> AccountIds2){

assId = [select id,AccountId from Asset where AccountId in:accountIds2];
for(Asset accId : assId)
{
    if(mapAccount.containsKey(accId.AccountId))
    {
        integer sum;
        sum = mapAccount.get(accId.AccountId);
        sum = sum+1;
        mapAccount.put(accId.AccountId,sum);
    }
    else
    {
        integer sum;
        sum = 1;
        mapAccount.put(accId.AccountId,sum);
    }
 }


 return mapAccount;
}
}

 

Thanks  in advance !

 

Regards,

Rsk

Hi,

Hope any one can help me with this.

I wish to generate a report of attachments within emails( from Case Emails).  Is there a way to do this and if so how is it done.

 

Thanks a ton in advance!

 

 

Regards,

Kumar

Hi,

 

I am unable to figure out how i can write test methods to cover code for my wrapper/inner class. It covers only 73 % and the highlighted (in red color) part is not covered. Can any one point me in the right direction?



public class showAsPDF_Cls {

  List<Case> cs = new List<Case>();
  Id Assid;
 
   public class WrapperCases{
       public Integer Count{set;get;}
       public Case CaseDetails{set;get;}
    }
    public List<WrapperCases> wrapperlist = new List<WrapperCases>();
 
   
    public showAsPDF_Cls(ApexPages.StandardController controller) {
      Assid = apexPages.currentPage().getParameters().get('id');
      cs = [select Serial_Number__c,Product_Lookup__c,Firmware_Version__c,CaseNumber,OwnerId,Status,CreatedDate,ClosedDate,Description,Resolution_Summary__c,DTS_c__c FROM Case where AssetId =: Assid order by CreatedDate ];
     
     
      for(Integer i=0; i<cs.size();i++){
           WrapperCases wp = new WrapperCases();
           wp.Count= i+1;
           wp.CaseDetails= cs[i];
           wrapperlist.add(wp);     
      }
     
    }
    public List<WrapperCases> getList(){
      return wrapperlist;  
    }
   

     static testMethod void testPDF(){
      Account acc = new Account(Name= 'Sample Acc');
      insert acc;
      pageReference p = system.CurrentPagereference();
      p.getParameters().put('id',acc.Id);
      Case c = new Case(status='test');
      insert c;

      WrapperCases w = New WrapperCases();
      List<WrapperCases> wlist = new List<WrapperCases>();
      w.count = 1;
      w.CaseDetails= c;
      wlist.add(w);
      ApexPages.StandardController QController = new ApexPages.StandardController(c);
      showAsPDF_Cls s = new showAsPDF_Cls(QController);
      s.getList();
    }
}

 

 

Any help is highly appreciated.

 

 

Thanks,

Kumar.

Hi,

 

I want to display a value of Standard Number/currency field without ','.

Example 10000 instead of 10,000 as field value.

How can I do this ?

 

Any help must be highly appreciated.

 

 

Thanks,

Kumar

Hi,

 

I'm facing an issue while passing parameters with <apex:outputLink> to a VF page , if the parameter value having the '&' char  ( For example : CompanyName is P & B Computers), it takes '&' as a separator and displays only the text before '&' (ex:  P as the CompanyName).

 

Here is the Code :

 

<apex:outputLink value="/apex/CompanyPage_VF?companyName={!a.companyName}&street={!a.street}&city={!a.City}&state={!a.State}&country={!a.Country}" id="theLink">
             Click Here
          </apex:outputLink> 

 

Any help must be appreciated.

 

Thanks

Kumar




Hi,

I'm displaying list of Cases of Account as Pdf by using renderAs attribute on Apex Page, but found lot of garbage at the bottom of the PDF file like

 

JanFeb....Dec,

Sun,Mon...Sat,

Today

I want to clean up all this garbage on the PDF. Any help must be highly appreciated.

 

Thanks In Advance,

Kumar.

 Hi, I need to remove special characters in a string ?, do we have any apex methods to remove spl characters ? Or any alternate solution ?.

Any help is highly appreciated.

 

Thanks In Advance,

Kumar

Hi,

I am trying to make a callout from APEX to an HTTP endpoint(Hoover's API)  but am receiving the following error:

 
 500, internal server error'.

Here is my Apex class :



global public with sharing class HttpCallout_CLS {

    Public static void sendRequest(){
   
    String API_KEY = 'XXX';
   
    String env;
    env =  '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://applications.dnb.com/webservice/schema/">'+
             '<soapenv:Header>'+
                '<sch:API-KEY>XXX</sch:API-KEY>'+
             '</soapenv:Header>'+
             '<soapenv:Body>'+
               '<sch:FindCompanyByKeywordRequest>'+
                 '<sch:sortDirection>Ascending</sch:sortDirection>'+

                 '<sch:keyword>xyz</sch:keyword>'+

- Hide quoted text -

                 '<sch:searchBy>companyName</sch:searchBy>'+
                 '<sch:returnSearchNavigation>false</sch:returnSearchNavigation>'+
                 '<sch:orderBy xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>'+
                 '<sch:searchNavigation>'+
                   '<sch:employeeSearchNavigation>'+
                   '</sch:employeeSearchNavigation>'+
                   '<sch:ownershipTypeSearchNavigation>'+
                   '</sch:ownershipTypeSearchNavigation>'+
                   '<sch:locationTypeSearchNavigation>'+
                   '</sch:locationTypeSearchNavigation>'+
                   '<sch:salesSearchNavigation>'+
                   '</sch:salesSearchNavigation>'+
                   '<sch:locationSearchNavigation>'+
                     '<sch:countryNavigation>'+
                       '<sch:countryNavigationValue>${#Project#countryNavigationValue}</sch:countryNavigationValue>'+
                       '<sch:stateNavigation>'+
                        '<sch:stateNavigationValue>${#Project#stateNavigationValue}</sch:stateNavigationValue>'+
                        '<sch:cityNavigation>'+
                          '<sch:cityNavigationValue>${#Project#cityNavigationValue}</sch:cityNavigationValue>'+
                        '</sch:cityNavigation>'+
                      '</sch:stateNavigation>'+
                    '</sch:countryNavigation>'+
                  '</sch:locationSearchNavigation>'+
                  '<sch:industrySearchNavigation>'+
                  '</sch:industrySearchNavigation>'+
                '</sch:searchNavigation>'+
              '</sch:FindCompanyByKeywordRequest>'+
            '</soapenv:Body>'+
          '</soapenv:Envelope>';
 
   Http h = new Http();
    HttpRequest req = new HttpRequest();
    req.setEndpoint('http://hapi.hoovers.com/HooversAPI-32');
    req.setMethod('POST');
    req.setBody(env);
    req.setTimeout(12000);
   
    Blob headerValue = Blob.valueOf(API_KEY);

    String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
    req.setHeader('Authorization',authorizationHeader);

       
    HTTPResponse res = h.send(req);
    System.debug(res.getBody());
    }
}




  I tried with username and password also, even though i'm facing the same issue. Has anyone experienced anything similar to this?.   Any help must be appreciated.

Thanks Inadvance,
Satheesh

I have set up the twitter for chatter & see the postings go back n forth . My question is how do i get the feeds to display on the profile page rather than having to go the twitter tab in salesforce to log in & see updates. Also any ideas on how to set up twitter to case creation?

 

Thanks