• Zeeshan Sayed 4
  • NEWBIE
  • -1 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
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 trying to call external rest webservice from salesforce. 
I have done following thing as,
1) set remote site settings
2) In code, passed authetication details for basic authentication.

whenever i try to access https://ap1.salesforce.com/ then I am getting success response from but when i try to access created rest service https://ap1.salesforce.com/services/apexrest/leads/createLead then I get unauthorized endpoint error message.

Error message for https://ap1.salesforce.com/services/apexrest/leads/createLead
 success message for 

Success message for https://ap1.salesforce.com/
User-added image


Please help me to solve this...Thanks