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
JComplianceJCompliance 

Having a Save Error for an Apex Class

I have created the following code. When I try to save I get  "Save Error: expecting a right parentheses, found 'true'"

 

} 

public class CloneProtocalArmActivities{

 

private Protocol_Arm__c contactClone = null;

private final Protocol_Arm__c contactBase = null;

 

public CloneProtocalArmActivities(ApexPages.StandardController controller) {

protocolarmBase = 

[SELECT Id, Protocol__c,

(SELECT Subject, WhoId, WhatId, ActivityDate, Status FROM Tasks)

FROMProtocol_Arm__c

WHERE Id = :ApexPages.currentPage().getParameters().get('Id')];

}

 

public PageReference cloneProtocolArm() {

protocolarmClone = protocolarmBase.clone(

false, // preserve ID

true// deep clone (all fields and relationships)

false, // preserve readonly timestamps

false  // preserve autonumbers

);

insert protocolarmClone;

        

if (!protocolarmBase.Tasks.isEmpty()) {

List<Task> tasks = protocolBase.Tasks.deepClone(

false, // preserve ID

false, // preserve readonly timestamps

false  // preserve autonumbers

);

for (Task t : tasks) { 

t.WhoId = protocolarmClone.Id; 

}

insert tasks;

}

}

PageReference newProtocolArmPage = new ApexPages.StandardController(protocolarmClone).view();

newProtocolArmPage.setRedirect(true);

       

return newProtocolArmPage;

}

 

Please help.

Best Answer chosen by Admin (Salesforce Developers) 
vishal@forcevishal@force
public class CloneProtocalArmActivities
{
    private Protocol_Arm__c contactClone = null;
    private final Protocol_Arm__c contactBase = null;

    public CloneProtocalArmActivities(ApexPages.StandardController controller)
    {

        protocolarmBase = [SELECT Id, Protocol__c,

        (SELECT Subject, WhoId, WhatId, ActivityDate, Status FROM Tasks)

        FROMProtocol_Arm__c

        WHERE Id = :ApexPages.currentPage().getParameters().get('Id')];

    }
    
    public PageReference cloneProtocolArm()
    {

        protocolarmClone = protocolarmBase.clone
        (

        false, // preserve ID

        true,  // deep clone (all fields and relationships)

        false, // preserve readonly timestamps

        false  // preserve autonumbers

        );

        insert protocolarmClone;

        if (!protocolarmBase.Tasks.isEmpty())
        {

            List<Task> tasks = protocolBase.Tasks.deepClone
            (

                false, // preserve ID

                false, // preserve readonly timestamps

                false  // preserve autonumbers

            );

            for (Task t : tasks)
            {

            t.WhoId = protocolarmClone.Id;

            }

            insert tasks;

        }
        PageReference newProtocolArmPage = new ApexPages.StandardController(protocolarmClone).view();

        newProtocolArmPage.setRedirect(true);

        return newProtocolArmPage;
    }
}

 This should save it for you.

All Answers

pankaj.raijadepankaj.raijade

I think it is because there is an extra '}' before 'PageReference newProtocolArmPage'

 

Please remove that and check.

 

Regards,

Pankaj Raijade

vishal@forcevishal@force
public class CloneProtocalArmActivities
{
    private Protocol_Arm__c contactClone = null;
    private final Protocol_Arm__c contactBase = null;

    public CloneProtocalArmActivities(ApexPages.StandardController controller)
    {

        protocolarmBase = [SELECT Id, Protocol__c,

        (SELECT Subject, WhoId, WhatId, ActivityDate, Status FROM Tasks)

        FROMProtocol_Arm__c

        WHERE Id = :ApexPages.currentPage().getParameters().get('Id')];

    }
    
    public PageReference cloneProtocolArm()
    {

        protocolarmClone = protocolarmBase.clone
        (

        false, // preserve ID

        true,  // deep clone (all fields and relationships)

        false, // preserve readonly timestamps

        false  // preserve autonumbers

        );

        insert protocolarmClone;

        if (!protocolarmBase.Tasks.isEmpty())
        {

            List<Task> tasks = protocolBase.Tasks.deepClone
            (

                false, // preserve ID

                false, // preserve readonly timestamps

                false  // preserve autonumbers

            );

            for (Task t : tasks)
            {

            t.WhoId = protocolarmClone.Id;

            }

            insert tasks;

        }
        PageReference newProtocolArmPage = new ApexPages.StandardController(protocolarmClone).view();

        newProtocolArmPage.setRedirect(true);

        return newProtocolArmPage;
    }
}

 This should save it for you.

This was selected as the best answer