function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sekharasekhara 

Trigger

Hi to all,

My requirement is If we check a check box in perticular profile of a account owner. Then if any of his employess r any one create a contact then Contact Name is same as account owner .

 

 

public class Cont
{
public static void cb(Contact[] c1)
{
for(Contact c2:c1)
{
user c3;
if(c3.Auto_save_account_owner__c == true)
{
c2.Owner == c3.Name;
update c2;
}
}  
}
}

 

Error Is :
 Comparison arguments must be compatible types: SOBJECT:User, String at line 10 column 1
saurabhEventsaurabhEvent

Please revisit the code, User c3 is not initialized before doing comparison

sekharasekhara

 

public class Cont
{
public static void cb(Contact[] c1)
{
for(Contact c2:c1)
{
user c3=[select id,Accountid,name,Auto_save_account_owner__c from user where Auto_save_account_owner__c=true limit 1];
c2.Ownerid = c3.Accountid;
update c2;
}
}
}

 

Here code is saving and while clicking the save button i standard page error is :

Apex trigger Cont caused an unexpected exception, contact your administrator: Cont: execution of AfterUpdate caused by: System.FinalException: Record is read-only: Class.Cont.cb: line 8, column 1 "