• N.V.V.L.Vinay Kumar
  • NEWBIE
  • 60 Points
  • Member since 2012

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 17
    Replies
Hi,
When i writing the trigger .In that trigger i write the Map
code
----------------------
trigger contactupdate on Contact (before update,After delete) 
{
  if(Trigger.isbefore && trigger.isupdate)
  {
      Map<Id,Account> my = new  Map<Id,Account>();
      //my = Trigger.newMap;
      list<contact>con = new list<contact>();
      list<contact> cons = [select id,phone,accountid from contact where accountid in:my.keySet()];
      for(contact c:cons)
      {
          c.phone = my.get(c.accountid).phone;
          con.add(c);
      }
      update con;
  }
    Map<Id,Account> deleteconn = new Map<Id,Account>();
        deleteconn = trigger.oldMap;
    if(Trigger.isAfter && Trigger.isdelete)
    {
         
      //list<contact>con = new list<contact>();
      list<contact> cons = [select id,phone,accountid from contact where accountid in:deleteconn.keySet()];  
        delete cons;
    }
}
when i save the following code it will display the error
Illegal assignment from Map<Id,Contact> to Map<Id,Account>
/* Provide summary of Number of Cases on Contacts record */ 

trigger CaseSumTrigger on Case(after delete, after insert, after undelete, 
after update) {

    Case [] cas;
    if (Trigger.isDelete) 
        cas= Trigger.old;
    else
        cas= Trigger.new;

    // get list of Contacts
    Set<ID> contIds = new Set<ID>();
    for (Case cs : cas) {
            contIds.add(cs.ContactId);
    }
    
    Map<ID, Case> CasesForContacts = new Map<ID, Case>([select Id
                                                            ,ContactId
                                                            from Case
                                                            where ContactId in :contIds]);

    Map<ID, Contact> contToUpdate = new Map<ID, Contact>([select Id
                                                                 ,items__c
                                                                  from Contact
                                                                  where Id in :contIds]);
                                                                 
    for (Contact  cont: contToUpdate.values()) {
        Set<ID> casIds = new Set<ID>();
        for (Case cs : CasesForContacts.values()) {
            if (cs.ContactId == cont.Id)
                casIds.add(cs.Id);
        }
        if (cont.items__c != casIds.size())
            cont.items__c = casIds.size();
    }

    update contToUpdate.values();

}

 

How/Where do i add the loop to get only CLOSED cases?

Thank you!

 

  • September 25, 2012
  • Like
  • 0
Hi,
When i writing the trigger .In that trigger i write the Map
code
----------------------
trigger contactupdate on Contact (before update,After delete) 
{
  if(Trigger.isbefore && trigger.isupdate)
  {
      Map<Id,Account> my = new  Map<Id,Account>();
      //my = Trigger.newMap;
      list<contact>con = new list<contact>();
      list<contact> cons = [select id,phone,accountid from contact where accountid in:my.keySet()];
      for(contact c:cons)
      {
          c.phone = my.get(c.accountid).phone;
          con.add(c);
      }
      update con;
  }
    Map<Id,Account> deleteconn = new Map<Id,Account>();
        deleteconn = trigger.oldMap;
    if(Trigger.isAfter && Trigger.isdelete)
    {
         
      //list<contact>con = new list<contact>();
      list<contact> cons = [select id,phone,accountid from contact where accountid in:deleteconn.keySet()];  
        delete cons;
    }
}
when i save the following code it will display the error
Illegal assignment from Map<Id,Contact> to Map<Id,Account>
Hi,

I have written a test class for getting History Records for the Purticular field. but it shows 'Null'. I have tried from some links but all will give the same result. Am i wrong somewhere?
 
public class batchDateplacedbackoncallTest
{
    public static Testmethod void mytest()
    {      
        VA_Matching__c vaMatchRec = new  VA_Matching__c(Client__c = accobj.id,status__c='Available',
                                                         VA__c = vaRec.id,
                                                         Date_added_to_On_Call_List__c=Date.parse('1/1/2015')
                                                         );
    insert vaMatchRec;
    vaMatchRec.status__c='Placed- Part time';
    update vaMatchRec;
    vaMatchRec.status__c='Available';
    update vaMatchRec; 

    List<VA_Matching__History> histList=new List<VA_Matching__History>();
     VA_Matching__History hist=new VA_Matching__History(Field='Status__c');
     histList.add(hist);
        
      List<String> results=example.processRows(histList);
     System.assertEquals(1, results.size());
     System.assertEquals('Name|null|null', results[0]);  
 }
}

 public List<VA_Matching__History> queryDatabase(id vaId)
    {
        return [select Id, OldValue, NewValue, Field, CreatedBy.Name 
                from VA_Matching__History
                where ParentId=:vaId order by createddate desc limit 1];
    }
   
     public List<String> ProcessRows(List<VA_Matching__History> historyList)
    {
        List<String> results=new List<String>();
        for (VA_Matching__History hist : historyList)
        {
            String field=hist.field;
            Object oldValue=hist.oldValue;
            Object newValue=hist.newValue;

            results.add(field + '|' + oldValue + '|' + newValue);
        }

        return results;
    }

Thank you so much.
 
I have a VFpage v1 where i am asking user to put values in textbox but not saving data in object on button click rather i am generating random number on other VFpage v2 and want to insert those(v1) records on this V2's button click.how to do this???
<td><apex:inputField value="{!child.batchObj.Asked_Qty__c}"/></td>
                                                   
<td><apex:inputfield value="{!child.batchObj.Quantity__c}"  required="{!child.batchObj.Asked_Qty__c=0}" style="width:110px"/></td>


When inputfield  "Asked_Qty__c" was empty .then "Quantity__c" was not required .

When inputfield  "Asked_Qty__c" was not empty .then "Quantity__c" was  required 

I want to do this asked quantity was entered by salesforce user ?

Based on input it should take required or not require  ?

How can i do this Thanks in Advance ?
 

Hi All,

I have one picklist field with values like PAN,TAN,VAT,etc.....And I need to write a validation rule for the format of PAN number for that picklist field.Is it possible?
I have written the below formula but didn't work
NOT(REGEX(ISPICKVAL(PANCARD__c ,"((([a-zA-Z]{5})\\d{4})[a-zA-Z]{1})"))
Any one has any idea?It's urgent

Thanks in advance

I have overridden the account view with my own visualforce page and i am noticing that the sandbox and the production environment handle the same code differently.

 

For example for the following bit of code in my VF page

 

<apex:tab style="background-color: #FFFFFF" label="Campaigns" name="Campaigns" id="tabCampaign" rendered="{!account.RecordtypeId == '012200000000RMCAA2'}">
            <apex:relatedList subject="{!account}" list="personCampaignMembers" />
</apex:tab>

 

In the Full Sandbox (Spring 13) the above code works and I am able to see the Campaign related list for Customer A

 

In Production I get the following error for the same Customer A: 'PersonCampaignMembers' is not a valid child relationship name for entity customer.

 

It works in production when i change:

<apex:relatedList subject="{!account}" list="personCampaignMembers" />

to

<apex:relatedList subject="{!account}" list="CampaignMembers" />

 

But the change then cause the same error in my full sandbox.

 

Is an issue with Spring 13 release? will they resolve it before it is released?

 

 

 

 

 

between the

  • January 28, 2013
  • Like
  • 0

I keep getting a null object error on this part of my controller but can't figure out why... 

 

I am trying to determine the age of the opportunity as CloseDate - CreateDate for closed opportunities and Today - Created Date for open opportunities. I can't quite figure out how any of these could be null... and in anycase I tried to account for that in the code but is still haunting me... 

 

 public integer getAge() {
    	date close;
    		if( opp.CloseDate == null) {close = system.today();} else {close = opp.CloseDate;}
    	integer openAge = date.valueof(opp.CreatedDate).daysbetween(opp.CloseDate);
    	integer closeAge = date.valueof(opp.CreatedDate).daysBetween(system.today());
        if(opp.isClosed == true && closeAge != null && openAge != null) { return closeAge; } else {return openAge;} 
    }   

Any pointers are greatly appreciated!

 

I have no clue why this won't work. I've tried it a couple ways. Basically, I'm just trying to change the record type of the account record to a specific record type whnever certain conditions are met. Is this even possible?

 

The first: 

trigger AccountRecordType on Account (after update) {
    
    List<RecordType> getRecordType = new List<RecordType>([SELECT Id, Name FROM RecordType WHERE Id = '01240000000DciMAAS']);
    List<Account> updateAccounts = new List<Account>();
    
    for(Account acc : trigger.new){
    	if (acc.Type == 'Client - Active'){
            for(Account aco : trigger.old){
            	if (aco.Account_RecordType__c == 'Prospect - Page 1 SEO'){
                    aco.RecordType = getRecordType[0];
                    updateAccounts.add(aco);
                }
            }
        }     	   
    }
    update updateAccounts;

}

 And this way:

 

trigger AccountRecordType on Account (after update) {
    
    List<Account> updateAccounts = new List<Account>();
    
    for(Account acc : trigger.new){
    	if (acc.Type == 'Client - Active'){
            for(Account aco : trigger.old){
            	if (aco.Account_RecordType__c == 'Prospect - Page 1 SEO'){
                    aco.RecordTypeId = '01240000000DciMAAS';
                    updateAccounts.add(aco);
                }
            }
        }     	   
    }
    update updateAccounts;

}

 

  • September 28, 2012
  • Like
  • 0

It is possible to select fields from different objects in one SOQL query (like a JOIN). Example:

 

SELECT Id, Name, CloseDate, Account.Name, SAPID__c, StageName  FROM Opportunity LIMIT 10

 

But how does one get these results in apex code? I have not found out how to declare the result set:

 

List<whichType> = [SELECT Id, Name, CloseDate, Account.Name, SAPID__c, StageName  FROM Opportunity LIMIT 10];

  • September 28, 2012
  • Like
  • 0

Take an example Student__c is an object and in that object having fied called Age__c.Then i have created validation rule on student object the age less than 18 the validation rule fire.It's working on standard page.now i have created custom visulaforce page with student object fields then i enter the data into the fields the validation is not fired.validation is an active mode but on custom visual force page the validation not working any idea thanks..................

  • September 26, 2012
  • Like
  • 0

Hi Their,

 

     I'm getting values from api automatically...In this I dont need all values to be displayed....I want only few values how can I acheive it

  

/* Provide summary of Number of Cases on Contacts record */ 

trigger CaseSumTrigger on Case(after delete, after insert, after undelete, 
after update) {

    Case [] cas;
    if (Trigger.isDelete) 
        cas= Trigger.old;
    else
        cas= Trigger.new;

    // get list of Contacts
    Set<ID> contIds = new Set<ID>();
    for (Case cs : cas) {
            contIds.add(cs.ContactId);
    }
    
    Map<ID, Case> CasesForContacts = new Map<ID, Case>([select Id
                                                            ,ContactId
                                                            from Case
                                                            where ContactId in :contIds]);

    Map<ID, Contact> contToUpdate = new Map<ID, Contact>([select Id
                                                                 ,items__c
                                                                  from Contact
                                                                  where Id in :contIds]);
                                                                 
    for (Contact  cont: contToUpdate.values()) {
        Set<ID> casIds = new Set<ID>();
        for (Case cs : CasesForContacts.values()) {
            if (cs.ContactId == cont.Id)
                casIds.add(cs.Id);
        }
        if (cont.items__c != casIds.size())
            cont.items__c = casIds.size();
    }

    update contToUpdate.values();

}

 

How/Where do i add the loop to get only CLOSED cases?

Thank you!

 

  • September 25, 2012
  • Like
  • 0

Hi,

 

I am doing one VF Page.In this one custom button is there.If I click on this button  it should open another visualforce page as popup window.

How can I acheive this.Can anyone please suggest me...

 

Thanks in Advance,

 

 

  • September 25, 2012
  • Like
  • 0