• Swathi A 8
  • NEWBIE
  • 30 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 18
    Questions
  • 10
    Replies
Hi new to salesforce I'm trying validation using trigger I'm getting above err
 my class code is
 @HttpPost
   global static void createUser(List<User> userList,String Firstname,String Lastname,  String alias,String ProfileId,String Email,
                                String   TimeZoneSidKey,String LanguageLocaleKey,String CommunityNickname,
                               String EmailEncodingKey,String LocaleSidKey,String UserName)
   {
       
       Profile customProfile = [Select id From profile Where Name ='Custom Profile' Limit 1];
       for(User newUser : userList){
        newUser.Firstname = firstname;
        newUser.Lastname = lastname;
        newUser.CommunityNickname = CommunityNickname;
        newUser.Email = email;
       if(String.isBlank(newUser.Email))
       {
           newUser.addError('Enter Email ');
       }
        newUser.Alias = alias;
        newUser.Username = username;
        newUser.ProfileId = customProfile.id ;
        newUser.TimeZoneSidKey = TimeZoneSidKey;
        newUser.LanguageLocaleKey = LanguageLocaleKey;
        newUser.EmailEncodingKey = EmailEncodingKey;
        newUser.LocaleSidKey = LocaleSidKey;
        insert newUser;
                                 
    }
   }
 please help me
 
my code
 @HttpPut
     global static Id upsertUser(String Firstname,String Lastname,  String alias,String ProfileId,String Email,
                                String   TimeZoneSidKey,String LanguageLocaleKey,
                               String EmailEncodingKey,String LocaleSidKey,String UserName)
   {
      
           User updateUser = new  User();
        updateUser.Firstname = firstname;
        updateUser.Lastname = lastname;
        updateUser.Email = email;
        updateUser.Alias = alias;
        updateUser.Username = username;
        updateUser.ProfileId = ProfileId ;
        updateUser.TimeZoneSidKey = TimeZoneSidKey;
        updateUser.LanguageLocaleKey = LanguageLocaleKey;
        updateUser.EmailEncodingKey = EmailEncodingKey;
        updateUser.LocaleSidKey = LocaleSidKey;
        upsert updateUser; 
           
        return updateUser.Id;                                
        
    }      
    
TriggeronContact: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, only portal users can be associated to a contact: [] Trigger.TriggeronContact: line 32, column 1

my code is
trigger TriggeronContact on Contact (After insert) {
    Set<ID> contactids = new Set<ID>();
    for(Contact c : Trigger.new){
        if(c.LastName != null ){
            Contactids.add(c.Id);
        }
    }
    List<Contact> conlist =[Select id, email,FirstName,LastName  from Contact where Id IN : contactids];
    List<User> userList = new List<User>();
    for(Contact con : trigger.new){
        string nick = con.email!=null?con.email.substring(0, con.email.indexOf('@')):''; 
        nick += Datetime.now().getTime();
        List<Profile> profileList = [Select Id from Profile where Name=: 'System Administrator' limit 1];
        
        User newuser = new User(Alias = con.FirstName,
                                email = con.Email,
                                emailencodingkey = 'UTF-8',
                                firstname = con.FirstName,
                                lastname = con.LastName,
                                localesidkey = 'en_US',
                                contactId = con.Id,
                                timezonesidkey='America/Los_Angeles',
                                IsActive = true,
                                username = con.Email,
                                CommunityNickname = nick,
                                ProfileId =  profileList[0].Id,
                                LanguageLocaleKey = 'en_US');
                          userList.add(newuser);
}
    insert userList;

}


how i need to clear this err msg
trigger CustomerDetailName on Customer_Detail__c (Before insert,after insert) {
    List<Dup_Customer_Detail__c> dupList = new List<Dup_Customer_Detail__c>();
    for(Customer_Detail__c customer : trigger.new){
        if(trigger.IsBefore && trigger.isInsert){
        customer.Name= customer.Name + '.' + customer.Last_name__c;
    }
      else  if(trigger.IsAfter && trigger.isInsert){
        Dup_Customer_Detail__c dup =new Dup_Customer_Detail__c();
        dup.Name = customer.Name;
        dup.Last_Name__c = customer.Last_name__c;
        
        dupList.add(dup);
    
    }
  
    }
    if(!dupList.isEmpty()){
    insert dupList;
    }
trigger AccountCustomerDetail on Customer_Detail__c (before insert) {
    set<id>accountId = new set<id>();
    for(Customer_Detail__c customer : trigger.new){
        accountId.add(customer.id);
    }
List<Account> acclist = [Select id,BillingStreet,BillingCity from Account 
                        where id in: accountId];
    Map<id,Account>accMap = new Map<id,Account>();
    for(Account acc: trigger.new){
        accMap.put(acc.id, acc);
    }
    for(Customer_Detail__c customer : Trigger.new){
        customer.APShipping_Street__c = accMap.get(customer.Id).BillingStreet;
        customer.AP_Shipping_City__c = accMap.get(customer.Id).BillingCity;
    }
}

Err is  Line 9 Invalid loop variable type expected Customer_Detail__c was Account. Please help me to solve this.
my code

public class CollegeActions {
   public static boolean flag = true;
    public static void createMarkSheet(List<college__c> collegeList ){
        List<Mark_Sheet__c> marksheetList = new List<Mark_Sheet__c>();
        for(college__c college :collegeList ){
            Mark_Sheet__c mark = new Mark_Sheet__c();
            mark.Name = college.Name;
            mark.Last_Name__c = college.Last_Name__c;
            marksheetList.add(mark);
            
        }
        if(!marksheetList.isEmpty()){
          insert marksheetList;
            
        }
        
        }
    }

In trigger 

trigger collegeInsertTrigger on college__c (after insert,after update) {
        if( CollegeActions.flag== True)
    {
        CollegeActions.flag = false;
         CollegeActions.createMarkSheet(Trigger.new);
    }
}

 
User-added image  even I created  separate class  for recursion basic code public class CheckRecursive {
  
    public Static Boolean firstcall = false;
    
}
What im missing here? User-added image
Hi new to salesforce I'm trying validation using trigger I'm getting above err
 my class code is
 @HttpPost
   global static void createUser(List<User> userList,String Firstname,String Lastname,  String alias,String ProfileId,String Email,
                                String   TimeZoneSidKey,String LanguageLocaleKey,String CommunityNickname,
                               String EmailEncodingKey,String LocaleSidKey,String UserName)
   {
       
       Profile customProfile = [Select id From profile Where Name ='Custom Profile' Limit 1];
       for(User newUser : userList){
        newUser.Firstname = firstname;
        newUser.Lastname = lastname;
        newUser.CommunityNickname = CommunityNickname;
        newUser.Email = email;
       if(String.isBlank(newUser.Email))
       {
           newUser.addError('Enter Email ');
       }
        newUser.Alias = alias;
        newUser.Username = username;
        newUser.ProfileId = customProfile.id ;
        newUser.TimeZoneSidKey = TimeZoneSidKey;
        newUser.LanguageLocaleKey = LanguageLocaleKey;
        newUser.EmailEncodingKey = EmailEncodingKey;
        newUser.LocaleSidKey = LocaleSidKey;
        insert newUser;
                                 
    }
   }
 please help me
 
my code
 @HttpPut
     global static Id upsertUser(String Firstname,String Lastname,  String alias,String ProfileId,String Email,
                                String   TimeZoneSidKey,String LanguageLocaleKey,
                               String EmailEncodingKey,String LocaleSidKey,String UserName)
   {
      
           User updateUser = new  User();
        updateUser.Firstname = firstname;
        updateUser.Lastname = lastname;
        updateUser.Email = email;
        updateUser.Alias = alias;
        updateUser.Username = username;
        updateUser.ProfileId = ProfileId ;
        updateUser.TimeZoneSidKey = TimeZoneSidKey;
        updateUser.LanguageLocaleKey = LanguageLocaleKey;
        updateUser.EmailEncodingKey = EmailEncodingKey;
        updateUser.LocaleSidKey = LocaleSidKey;
        upsert updateUser; 
           
        return updateUser.Id;                                
        
    }      
    
TriggeronContact: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, only portal users can be associated to a contact: [] Trigger.TriggeronContact: line 32, column 1

my code is
trigger TriggeronContact on Contact (After insert) {
    Set<ID> contactids = new Set<ID>();
    for(Contact c : Trigger.new){
        if(c.LastName != null ){
            Contactids.add(c.Id);
        }
    }
    List<Contact> conlist =[Select id, email,FirstName,LastName  from Contact where Id IN : contactids];
    List<User> userList = new List<User>();
    for(Contact con : trigger.new){
        string nick = con.email!=null?con.email.substring(0, con.email.indexOf('@')):''; 
        nick += Datetime.now().getTime();
        List<Profile> profileList = [Select Id from Profile where Name=: 'System Administrator' limit 1];
        
        User newuser = new User(Alias = con.FirstName,
                                email = con.Email,
                                emailencodingkey = 'UTF-8',
                                firstname = con.FirstName,
                                lastname = con.LastName,
                                localesidkey = 'en_US',
                                contactId = con.Id,
                                timezonesidkey='America/Los_Angeles',
                                IsActive = true,
                                username = con.Email,
                                CommunityNickname = nick,
                                ProfileId =  profileList[0].Id,
                                LanguageLocaleKey = 'en_US');
                          userList.add(newuser);
}
    insert userList;

}


how i need to clear this err msg
trigger AccountCustomerDetail on Customer_Detail__c (before insert) {
    set<id>accountId = new set<id>();
    for(Customer_Detail__c customer : trigger.new){
        accountId.add(customer.id);
    }
List<Account> acclist = [Select id,BillingStreet,BillingCity from Account 
                        where id in: accountId];
    Map<id,Account>accMap = new Map<id,Account>();
    for(Account acc: trigger.new){
        accMap.put(acc.id, acc);
    }
    for(Customer_Detail__c customer : Trigger.new){
        customer.APShipping_Street__c = accMap.get(customer.Id).BillingStreet;
        customer.AP_Shipping_City__c = accMap.get(customer.Id).BillingCity;
    }
}

Err is  Line 9 Invalid loop variable type expected Customer_Detail__c was Account. Please help me to solve this.
Greetings:

I have been trying to do check the challenge of the the first part of the "Apex Basics & Database" module. I have been restructuring my apex code but nothing seems to work. This is the error that I'm getting:
User-added image