• m@x~W0W~
  • NEWBIE
  • 10 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 7
    Replies
trigger updateContactCount on Contact (after insert, after delete)
{
    
    Set<id> accIds = new Set<id>();
     for (Contact a : Trigger.new)
     {
        accIds.add(a.Account.id); 
     }   

        Map<Id, Integer> accConMap = new Map<Id, Integer>();    
    
    for(AggregateResult ar : [SELECT Count(id) cnt, AccountId accId FROM Contact WHERE AccountId IN :accIds Group By AccountId] )
    {
        accConMap.put(String.valueOf(ar.get('accId')), Integer.valueOf(ar.get('cnt')));
    }
    
    
       // Map<id, Integer> cnt = new Map<id, Integer>([Select count() from Contact where Account.id in: accIds]); 
        for(id a : accIds)
        {
            Account.CountContact__c = accConMap.get(a);
        }   

}

 Please suggest. 

<apex:page standardStylesheets="true" tabStyle="Customer_Details__c" sidebar="false" showHeader="true" Controller="merchantService">
    <apex:form >
        <apex:pageMessages />
        <apex:pageBlock >
            <apex:pageBlockSection columns="1">
                <apex:pageBlockSection title="Customer Details" Collapsible="False">
                    <apex:inputField value="{!cusDet.First_Name__c}" required="true"/>
                    <apex:inputField value="{!cusDet.Last_Name__c}"/>
                    <apex:inputField value="{!cusDet.Email_ID__c}"/>    
                    <apex:inputField value="{!cusDet.Contact_No__c}"/>   
                </apex:pageBlockSection>
                
                <apex:pageBlockSection title="Product Details" collapsible="false" columns="3">
                    <apex:inputField style="width : 225px" value="{!proDet.Name}" required="true"/>
                    <apex:inputField style="width : 300px" value="{!proDet.Unit_Price__c}"/>
                    <apex:inputField style="width : 375px" Value="{!proDet.Quantity__c}"/>
                </apex:pageBlockSection>
                <apex:pageBlockSection >
                    <apex:commandButton style="float:right;" value="Add Row"/>
                    <apex:commandButton style="float:left;" value="Delete Row"/>
                </apex:pageBlockSection>  
            </apex:pageBlockSection>  
        </apex:pageBlock>
           <center>
              <apex:commandButton value="Save" action="{!save}"/>
              <apex:commandButton value="Generate Receipt"/>
              <input class="btn" type="reset" value="Reset"/>
           </center>
    </apex:form>
</apex:page>

 

public class merchantService
{
         
   public Customer_Details__c cusDet{ get; set;}
   public Product_Detail__c proDet{get; set;} 
    
    public merchantService()
    {
    cusDet = new Customer_Details__c();
    proDet = new Product_Detail__c();
    }                        
    public PageReference save() 
    {
        //try {
             insert cusDet;
             proDet.Customer_Name__c = cusDet.First_Name__c;
             upsert proDet;
             ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.INFO,'Save Successful.');
             ApexPages.addMessage(myMsg);
        //    } 
       // catch(System.DMLException e) 
       //    {
       //     ApexPages.addMessages(e);
        //    return null;
         //   }
            // After Save, navigate to the default view page:
            //return (new ApexPages.StandardController(pinfo)).view();
            return null;
    }  
}Here ,
First_Name__c is not unique.
Email_ID__c is unique.
 
 
Whenever I'm changing just the email id (First name unchanged) it gives the below error. But if I change the name too then it works fine.
 
Please suggest .
 
23:43:37:131 EXCEPTION_THROWN [4]|System.DmlException: Insert failed. First exception on row 0 with id 0019000000H6g5WAAR; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]
trigger teachHindi on Contact (before insert, before update) 
{
//////////////////////////////////////
// Do not allow any teacher to insert/update if that teacher is teaching Hindi.
// Created 20131009 max
// Modified 20131009
//////////////////////////////////////
    if(Trigger.isBefore && Trigger.isInsert)
    {
        for (Contact cont : Trigger.new)
        {            
            if(cont.Subject__c == null)
            {
                cont.addError('Subject Field Cannot be left blank');
            }
            
            else if(cont.Subject__c.Contains('Hindi'))
            {
                cont.addError('can\'t insert as hindi is taught');
            }
        }
    }
    else if (Trigger.isBefore && Trigger.isUpdate)
    {
        for (Contact cont : Trigger.new)
        {
           if(cont.Subject__c == null)
            {
                cont.addError('Subject Field Cannot be left blank');
            }
            
            else if(cont.Subject__c.Contains('Hindi'))
            {
                cont.addError('can\'t insert as hindi is taught');
            }
        } 
    }
}

 

System.NullPointerException: Attempt to de-reference a null object: Trigger.updateCount: line 13, column 1

 

 

trigger updateCount on Student__c (after insert, before delete)
{
//////////////////////////////////////
// When insert/update any student’s in class then update MyCount Accordingly.
// Created 20131009 max
// Modified 20131009
//////////////////////////////////////
if(Trigger.isAfter && Trigger.isInsert)
{
for (Student__c stent : Trigger.new)
{
Id cid = stent.Class__c;
Integer clist = [Select Count() FROM Student__c where Class__c =: cid ];
//stent.Class__r.My_Count__c = clist;
}
}
else if(Trigger.isAfter && Trigger.isDelete)
{
for (Student__c stent : Trigger.new)
{
Id cid = stent.Class__c;
Integer clist = [Select Count() FROM Student__c where Class__c =: cid ];
//stent.Class__r.My_Count__c = clist;
}
}

}

Review all error messages below to correct your data. Apex trigger stuLimit caused an unexpected exception, contact your administrator: stuLimit: execution of BeforeInsert caused by: System.TypeException: Invalid integer: [Class__c (Number_Of_Students__c:2, Max_Size__c:2, Id:a0190000007tbH3AAI)]: Trigger.stuLimit: line 15, column 1m

 

 

 

trigger stuLimit on Student__c (after insert)
{
//////////////////////////////////////
// Do not allow insert student if class already reached MaxLimit.
// Created 20131009 max
// Modified 20131009
//////////////////////////////////////
if(Trigger.isAfter && Trigger.isInsert)
{
for (Student__c std : Trigger.new)
{
Id cid = std.class__c;
list<Class__c> cls=[SELECT Max_Size__c, Number_Of_Students__c from Class__c where class__c.id = : cid];
if(Integer.Valueof(cls.get(0)) <= Integer.Valueof(cls.get(1)))
{
std.addError('can\'t insert Class has already reached it\'s maximum limit');
}
}
}

}

public class AsgClass2
{
List<Class__c> clid = [Select id from Class__c];
map<id,Set<Student__c>> newMap = new map<id,Set<Student__c>>();
public map<id, Set<Student__c>> trdata()
{
for(class__c cl:clid)
{
Set<Student__c> stset = [Select id from Student__c where Class__c = :cl.id];
newMap.put(cl.id,stset);
}

return newMap;
}
}

We are using Native Live Agent with Service Cloud Console.

Create a deployment and button and deployed to our test portal page.

In our setup, under deployment, added a value for Chat Window title; however, it doesn't seem to display when using IE8.  Displays the URL of the live agent host instead

It does display when using Firebox.

Any thoughts/ideas on how to fix

thanx in advance
max

SELECT First_Name__c, Name From Student__c WHERE Class__r.Name IN (SELECT Class__r.Name FROM Teaches__c WHERE Subject__c IN ('Hindi','Maths'))

 

 

Doesn't works???

<apex:page standardStylesheets="true" tabStyle="Customer_Details__c" sidebar="false" showHeader="true" Controller="merchantService">
    <apex:form >
        <apex:pageMessages />
        <apex:pageBlock >
            <apex:pageBlockSection columns="1">
                <apex:pageBlockSection title="Customer Details" Collapsible="False">
                    <apex:inputField value="{!cusDet.First_Name__c}" required="true"/>
                    <apex:inputField value="{!cusDet.Last_Name__c}"/>
                    <apex:inputField value="{!cusDet.Email_ID__c}"/>    
                    <apex:inputField value="{!cusDet.Contact_No__c}"/>   
                </apex:pageBlockSection>
                
                <apex:pageBlockSection title="Product Details" collapsible="false" columns="3">
                    <apex:inputField style="width : 225px" value="{!proDet.Name}" required="true"/>
                    <apex:inputField style="width : 300px" value="{!proDet.Unit_Price__c}"/>
                    <apex:inputField style="width : 375px" Value="{!proDet.Quantity__c}"/>
                </apex:pageBlockSection>
                <apex:pageBlockSection >
                    <apex:commandButton style="float:right;" value="Add Row"/>
                    <apex:commandButton style="float:left;" value="Delete Row"/>
                </apex:pageBlockSection>  
            </apex:pageBlockSection>  
        </apex:pageBlock>
           <center>
              <apex:commandButton value="Save" action="{!save}"/>
              <apex:commandButton value="Generate Receipt"/>
              <input class="btn" type="reset" value="Reset"/>
           </center>
    </apex:form>
</apex:page>

 

public class merchantService
{
         
   public Customer_Details__c cusDet{ get; set;}
   public Product_Detail__c proDet{get; set;} 
    
    public merchantService()
    {
    cusDet = new Customer_Details__c();
    proDet = new Product_Detail__c();
    }                        
    public PageReference save() 
    {
        //try {
             insert cusDet;
             proDet.Customer_Name__c = cusDet.First_Name__c;
             upsert proDet;
             ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.INFO,'Save Successful.');
             ApexPages.addMessage(myMsg);
        //    } 
       // catch(System.DMLException e) 
       //    {
       //     ApexPages.addMessages(e);
        //    return null;
         //   }
            // After Save, navigate to the default view page:
            //return (new ApexPages.StandardController(pinfo)).view();
            return null;
    }  
}Here ,
First_Name__c is not unique.
Email_ID__c is unique.
 
 
Whenever I'm changing just the email id (First name unchanged) it gives the below error. But if I change the name too then it works fine.
 
Please suggest .
 
23:43:37:131 EXCEPTION_THROWN [4]|System.DmlException: Insert failed. First exception on row 0 with id 0019000000H6g5WAAR; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]

System.NullPointerException: Attempt to de-reference a null object: Trigger.updateCount: line 13, column 1

 

 

trigger updateCount on Student__c (after insert, before delete)
{
//////////////////////////////////////
// When insert/update any student’s in class then update MyCount Accordingly.
// Created 20131009 max
// Modified 20131009
//////////////////////////////////////
if(Trigger.isAfter && Trigger.isInsert)
{
for (Student__c stent : Trigger.new)
{
Id cid = stent.Class__c;
Integer clist = [Select Count() FROM Student__c where Class__c =: cid ];
//stent.Class__r.My_Count__c = clist;
}
}
else if(Trigger.isAfter && Trigger.isDelete)
{
for (Student__c stent : Trigger.new)
{
Id cid = stent.Class__c;
Integer clist = [Select Count() FROM Student__c where Class__c =: cid ];
//stent.Class__r.My_Count__c = clist;
}
}

}

Review all error messages below to correct your data. Apex trigger stuLimit caused an unexpected exception, contact your administrator: stuLimit: execution of BeforeInsert caused by: System.TypeException: Invalid integer: [Class__c (Number_Of_Students__c:2, Max_Size__c:2, Id:a0190000007tbH3AAI)]: Trigger.stuLimit: line 15, column 1m

 

 

 

trigger stuLimit on Student__c (after insert)
{
//////////////////////////////////////
// Do not allow insert student if class already reached MaxLimit.
// Created 20131009 max
// Modified 20131009
//////////////////////////////////////
if(Trigger.isAfter && Trigger.isInsert)
{
for (Student__c std : Trigger.new)
{
Id cid = std.class__c;
list<Class__c> cls=[SELECT Max_Size__c, Number_Of_Students__c from Class__c where class__c.id = : cid];
if(Integer.Valueof(cls.get(0)) <= Integer.Valueof(cls.get(1)))
{
std.addError('can\'t insert Class has already reached it\'s maximum limit');
}
}
}

}

public class AsgClass2
{
List<Class__c> clid = [Select id from Class__c];
map<id,Set<Student__c>> newMap = new map<id,Set<Student__c>>();
public map<id, Set<Student__c>> trdata()
{
for(class__c cl:clid)
{
Set<Student__c> stset = [Select id from Student__c where Class__c = :cl.id];
newMap.put(cl.id,stset);
}

return newMap;
}
}