• Ganesh Nazirkar 5
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Hi all just read carefully my question its bit challanging

consider I have one custom object 'Project__c' which contains some image files for a single record.let consider i have 10 files in that related files if I view details of that file there is one custom field 'Sort_order__c'
I want to avoid duplicate values for that Sort_order__c field and there is one condition we only have 1 to 10 Sort_order__c number we can not add greater than 10 and less than one.also we can not make field Unique because we have multiple records in same objects which contains multiple files.
So how can we do this through trigger.
in short my question is i want to add duplication on content version object and Sort_order__c field for a SINGLE record only.

one record = i can add 1 to 10 without duplicate value
second record = i can add 1 to 10 without duplicate value
3rd record = i can add 1 to 10 without duplicate value
..........
Note : please do the changes in your org then add your comment
Hi all just read carefully my question its bit challanging

consider I have one custom object 'Project__c' which contains some image files for a single record.let consider i have 10 files in that related files if I view details of that file there is one custom field 'Sort_order__c'
I want to avoid duplicate values for that Sort_order__c field and there is one condition we only have 1 to 10 Sort_order__c number we can not add greater than 10 and less than one.also we can not make field Unique because we have multiple records in same objects which contains multiple files.
So how can we do this through trigger.
in short my question is i want to add duplication on content version object and Sort_order__c field for a SINGLE record only.

one record = i can add 1 to 10 without duplicate value
second record = i can add 1 to 10 without duplicate value
3rd record = i can add 1 to 10 without duplicate value
..........
Note : please do the changes in your org then add your comment
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