• Pathan S
  • NEWBIE
  • 25 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 10
    Replies
Getting Error---Illegal assignment from Decimal to String
I Created one object n auto number field.
trigger Records on Student__c(before insert,before delete)
    {
        List<Student__c> cp = new List<Student__c>();
        set<id> id = new set<id>();
        List <AggregateResult> requirements = new List<AggregateResult>();
        
       if (Trigger.isBefore && Trigger.isInsert)
       {
        List <Student__c> reqSize = [select id,NO_of_Student__c from Student__c];
        for(Student__c pt:trigger.new)
        {
         requirements=[select Count(NO_of_Student__c) from Student__c];
         system.debug('+++++++++++'+requirements.size());
         system.debug('++++++reqSize+++++'+reqSize.size());
         if(requirements.size() > 0)
         {
         for(AggregateResult ar:requirements)
         {
         pt.NO_of_Student__c = Decimal.ValueOf(String.ValueOf(ar.get('expr0')))+1;
          }
      }
         if(reqSize.size() <= 0){
          pt.NO_of_Student__c = 1;
         }
      }
}
      if (Trigger.isBefore && Trigger.isDelete)
      {
         List<Student__c> allRecs = [select id,NO_of_Student__c from Student__c where id not in: trigger.oldmap.keyset()];
         Map<Decimal,Student__c> RecMap = new Map<Decimal,Student__c>();
                 
         for(Student__c rcs: allRecs){
              
              RecMap.put(rcs.NO_of_Student__c,rcs);
         }
         for(Student__c pt1:trigger.old)
          {
              for(Student__c rc : allRecs){
                  if(rc.NO_of_Student__c > pt1.NO_of_Student__c){
                      rc.NO_of_Student__c-=  1;
                  }
              }
        
        
          }
          update allRecs;
          }   
     }
I created a one auto number field name(No of students).when i created a record   auto number is generating as auto.then created a 5 records then i deleted  one record Ex.0004. then again i created new rcord but is contunue auto.but i want to re allocate which record number(0004) are deleted. when i creat new record it will be take as a new record 0004.plz give reply.
vladidation rule (opprtunity..field...Val_1)for if we enter previous date than todays  date it  should be error..plz reply.
How to get notification or email alerts when I modified or Updated records in salesforce Opportunity.where i can write rule or validation..plz reply.
Getting Error---Illegal assignment from Decimal to String
I Created one object n auto number field.
trigger Records on Student__c(before insert,before delete)
    {
        List<Student__c> cp = new List<Student__c>();
        set<id> id = new set<id>();
        List <AggregateResult> requirements = new List<AggregateResult>();
        
       if (Trigger.isBefore && Trigger.isInsert)
       {
        List <Student__c> reqSize = [select id,NO_of_Student__c from Student__c];
        for(Student__c pt:trigger.new)
        {
         requirements=[select Count(NO_of_Student__c) from Student__c];
         system.debug('+++++++++++'+requirements.size());
         system.debug('++++++reqSize+++++'+reqSize.size());
         if(requirements.size() > 0)
         {
         for(AggregateResult ar:requirements)
         {
         pt.NO_of_Student__c = Decimal.ValueOf(String.ValueOf(ar.get('expr0')))+1;
          }
      }
         if(reqSize.size() <= 0){
          pt.NO_of_Student__c = 1;
         }
      }
}
      if (Trigger.isBefore && Trigger.isDelete)
      {
         List<Student__c> allRecs = [select id,NO_of_Student__c from Student__c where id not in: trigger.oldmap.keyset()];
         Map<Decimal,Student__c> RecMap = new Map<Decimal,Student__c>();
                 
         for(Student__c rcs: allRecs){
              
              RecMap.put(rcs.NO_of_Student__c,rcs);
         }
         for(Student__c pt1:trigger.old)
          {
              for(Student__c rc : allRecs){
                  if(rc.NO_of_Student__c > pt1.NO_of_Student__c){
                      rc.NO_of_Student__c-=  1;
                  }
              }
        
        
          }
          update allRecs;
          }   
     }
Hi all,

I would need help with this formula. I get a message: Syntax error. Any idea, please?

IF ( PotentialCOMAPABudget__c  < 200.000,"Bajo",

IF ( PotentialCOMAPABudget__c > 200.000 < 1.000.000, "Medio", 

IF ( PotentialCOMAPABudget__c > 1.000.000, "Alto",

IF (  PotentialCOMAPABudget__c > 5.000.000, "Key Account", null

)
)
)
)
  • February 03, 2017
  • Like
  • 0
vladidation rule (opprtunity..field...Val_1)for if we enter previous date than todays  date it  should be error..plz reply.
Hi,
  I need to autopopulate the number datatype field after the record is deleted.
For example,
I have 5 records and their serial numbers are  1,2,3,4 and 5. If i delete the 3rd record , then the serial number of the 4th record should be automatically populated as 3 and 5th records as 4.
How to achieve this delete operation?

My Trigger Code:

trigger RecordSteps on Record__c(before insert,after delete) 
    {
        List<Record__c> cp = new List<Record__c>(); 
        set<id> id = new set<id>();
        List <AggregateResult> requirements = new List<AggregateResult>();  
       if (Trigger.isBefore && Trigger.isInsert)
       { 
        for(Record__c pt:trigger.new)
        {
         requirements=[select Count(Seq__c) from Record__c];
         if(requirements.size() > 0)
         {
         for(AggregateResult ar:requirements)
         {
         pt.Seq__c = Decimal.ValueOf(String.ValueOf(ar.get('expr0')));
          }
      }
      }
}
      if (Trigger.isAfter&& Trigger.isDelete) 
      {
      for(Record__c pt1:trigger.old)
        {
          }
          }   
     }
Hi All,

I want to display number of contacts associated with an account using triggers.

for this I had created a lookup field like noofcontacts__c in account  object. and Wrote code as

trigger numberofcontacts on contact(after insert, after update, after delete) {
    Map<Id, List<Contact>> AcctContactList = new Map<Id, List<Contact>>();
    Set<Id> AcctIds = new Set<Id>();   
    List<schema.Account> AcctList = new List<schema.Account>();
    List<schema.Contact> ConList = new List<schema.Contact>();
   
    if(trigger.isInsert || trigger.isUPdate) {
        for(Contact Con : trigger.New) {
            if(String.isNotBlank(Con.AccountId)){
                AcctIds.add(Con.AccountId); 
            }  
        } 
    }
   
    if(trigger.isDelete) {
        for(Contact Con : trigger.Old) {
            AcctIds.add(Con.AccountId);    
        } 
    }          
   
    if(AcctIds.size() > 0){
        ConList = [SELECT Id, AccountId FROM Contact WHERE AccountId IN : AcctIds];
       
        for(Contact Con : ConList) {
            if(!AcctContactList.containsKey(Con.AccountId)){
                AcctContactList.put(Con.AccountId, new List<Contact>());
            }
            AcctContactList.get(Con.AccountId).add(Con);     
        }                          
      
           
        AcctList = [SELECT noofContacts__c FROM Account WHERE Id IN : AcctIds];
        for(Account Acc : AcctList) {
            List<schema.Contact> ContList = new List<schema.Contact>();
            ContList = AcctContactList.get(Acc.Id);
            Acc.Number_of_Contacts__c = ContList.size();
        }   
       
      
        update AcctList;   
    }

}
 I am   getting an error as "Variable doesnot exist:id".

Kindly support and suggest.

Thanks

Hi,

I am currently using the Salesforce Live Agent. I have successfully setup the administrator and the operator accounts and am able to establish the chat from a site that is Customer Portal enabled.

What I need is to display the logged in user name and context on the operator console when a chat invite is accepted by the operator. Currently it displays the name as  "visitor:" beside the visitor's message. Can I have the name of the Logged in User here. Also I need the contact associated with the User to be displayed. How do I establish the connection with my salesforce org so that I can achieve this.

I also need to route the chat to the appropriate operator based on certain parameters of the logged in user. Ex I need to route the chat to the account owner of the visitor. I can see only the default routing(based on departments) and a way to route based on their current chat activity. Is there any other way to specify custom routing?

Any help would be greatly appreciated.
Regards,

When someone takes the time/effort to repspond to your question, you should take the time/effort to either mark the question as "Solved", or post a Follow-Up with addtional information.  

 

That way people with a similar question can find the Solution without having to re-post the same question again and again. And the people who reply to your post know that the issue has been resolved and they can stop working on it. 


Roll-up summary fields are wrong in a certain case.

It relates to many:many relationships and cascading deletes.

Here's a stripped-down test case (not quite real world, but almost identical to the more complicated real thing):

We want a new object, "PhoneNumber", which normalizes all unique Phone numbers found in Contact records.  It is required that the PhoneNumber object has a roll-up summary field, "Contact Count", which gives the current number of Contacts with that phone number (in their phone/mobile/business etc fields).  This is a many:many relationship because multiple Contacts can have the same phone number, and a Contact has multiple phone numbers.

Expressing this relationship requires two custom objects in Salesforce.com:

PhoneNumber__c.Name             // the text string of the phone number
PhoneNumber__c.ContactCt0__c    // roll-up: COUNT Phone2Contact

Phone2Contact__c.PhoneNumber__c // Master-Detail(Phone Number)
Phone2Contact__c.Contact__c     // Lookup(Contact)


Triggers are used to maintain the "PhoneNumber" and "Phone2Contact" tables.

The problem occurs when a user deletes an Account.  All of the Contacts in the Account are deleted, but no triggers are fired for the Contact deletion.  I could write a trigger on Account delete/undelete, but if the Account has too many Contacts the trigger will fail.  (see this post).

Of course, the Phone2Contact records would be cascase-deleted IF Phone2Contact were defined in Master-Detail with the Contact, rather than the PhoneNumber, but the "Contact Count" roll-up summary requirement precludes this.


So those orphaned Phone2Contact__c records are not deleted.  However, they are updated - their Contact lookup field is set to null (actually, null-ish .. see below).  And, usefully, if the Account is undeleted - thus undeleting its Contacts - the Contact lookup field will be reset correctly.

So, if all my queries against Phone2Contact__c are careful to filter on Contact__c != null, that should give me what I need.


The problem lies in the "Contact Count" Roll-Up summary field.  It is no longer accurate, because the orphaned Phone2Contact records still exist (with a NULL Contact__c field).


I cannot define the roll-up as COUNT(Phone2Contact__c where Contact__c NOT EQUAL TO NULL) because "NULL" is interpreted here as a literal string rather than the null value.  There is no way to enter a blank string (or some signifier of null) into the "Value" field of the "not equal to" operator.  The only filter options available for a field of type lookup are equals / not equal to / starts with.


OK, so we get creative.  If we can't use a filtered "COUNT" roll-up, perhaps we can use a SUM roll-up that references a formula on Phone2Contact__c.

Let's add two fields to Phone2Contact__c:

Phone2Contact__c.ContactCt1__c // IF(ISNULL(Contact__c),0,1)
Phone2Contact__c.ContactCt2__c // IF(0 = len(Contact__c), 0, 1)


And let's roll them up into PhoneNumber:

PhoneNumber__c.ContactCt1__c    // roll-up: SUM Phone2Contact.ContactCt1__c
PhoneNumber__c.ContactCt2__c    // roll-up: SUM Phone2Contact.ContactCt2__c


Now let's see how all those fields behave in a test case:

Code:
public abstract class testPhoneNumber {

 private static testMethod void testAccountDelete() {
  // create a new Account (for easy delete/undelete)
  Account a = new Account(Name = 'Test Account 1');
  insert a;
  
  // create a new Contact in that account
  Contact c = new Contact(LastName = 'Test', AccountId = a.Id, Phone='(999)999-9999');
  insert c;

  // do what triggers would have done for us
  PhoneNumber__c p = new PhoneNumber__c(Name = c.Phone);
  insert p;
  Phone2Contact__c p2c = new Phone2Contact__c(Contact__c = c.Id, PhoneNumber__c = p.Id);
  insert p2c;

  
  dump(p2c.Id, 'before account delete');
  
  delete a;
  
  dump(p2c.Id, 'after account delete');

  undelete a;
    
  dump(p2c.Id, 'after account undelete');
  }

 private static void dump(Id id, string label) {
  Phone2Contact__c p2c = [select Contact__c, ContactCt1__c, ContactCt2__c
,PhoneNumber__r.ContactCt0__c, PhoneNumber__r.ContactCt1__c, PhoneNumber__r.ContactCt2__c
from Phone2Contact__c where Id = :id];
System.debug('\r\n\r\n' + label
+ '\r\n' + p2c.Contact__c + ' = p2c.Contact__c'
+ '\r\n' + p2c.ContactCt1__c + ' = count1 = IF(ISNULL(Contact__c),0,1)'
+ '\r\n' + p2c.ContactCt2__c + ' = count2 = IF(0 = len(Contact__c),0,1)'
+ '\r\n' + p2c.PhoneNumber__r.ContactCt0__c + ' = Roll-Up: COUNT(Phone2Contact)'
+ '\r\n' + p2c.PhoneNumber__r.ContactCt1__c + ' = Roll-Up: SUM(count1)'
+ '\r\n' + p2c.PhoneNumber__r.ContactCt2__c + ' = Roll-Up: SUM(count2)'
);
}

}

 
Here's the output (w/ comments added)


before account delete
0037000000VsRxwAAF = p2c.Contact__c
1.0 = count1 = IF(ISNULL(Contact__c),0,1)
1.0 = count2 = IF(0 = len(Contact__c),0,1)
1.0 = Roll-Up: COUNT(Phone2Contact)
1.0 = Roll-Up: SUM(count1)
1.0 = Roll-Up: SUM(count2)


after account delete
null = p2c.Contact__c
1.0 = count1 = IF(ISNULL(Contact__c),0,1)     // *1
0.0 = count2 = IF(0 = len(Contact__c),0,1)    // *2
1.0 = Roll-Up: COUNT(Phone2Contact)
1.0 = Roll-Up: SUM(count1)
1.0 = Roll-Up: SUM(count2)                    // *3


after account undelete
0037000000VsRxwAAF = p2c.Contact__c
1.0 = count1 = IF(ISNULL(Contact__c),0,1)
1.0 = count2 = IF(0 = len(Contact__c),0,1)
1.0 = Roll-Up: COUNT(Phone2Contact)
1.0 = Roll-Up: SUM(count1)
1.0 = Roll-Up: SUM(count2)



*1 ok, good to know, I guess the field is empty but not null ... although I thought that wasn't possible! (in SFDC all strings are trimmed prior to storage, and empty strings are converted to null)

*2 that's what we want on the child object

*3 BUG.  Why isn't this rolling up correctly?
  • February 08, 2008
  • Like
  • 0